Xcode saying that the variable "beacon" is undeclared? - ios

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated]
[[self.locationManager startRangingBeaconsInRegion: self.rangedRegion]
]}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidAppear:animated]
[[self.locationManager stopRangingBeaconsInRegion: self.rangedRegion]
]}
- (void)viewDidLoad
{
[super viewDidLoad];
self.tagname.text = [self.TagDetail objectForKey:#"Name"];
self.title = [self.TagDetail objectForKey:#"Name"];
NSString *proximity = #"near";
if ([beacon.proximity == CLProximityNear:]) {
NSLog(#"Show near");
[self.near setHidden:(NO)];
[self.far setHidden:(YES)];
[self.immediate setHidden:(YES)];
}
else if ([beacon.proximity == CLProximityFar]) {
NSLog(#"Show");
[self.near setHidden:(YES)];
[self.far setHidden:(NO)];
[self.immediate setHidden:(YES)];
}
else if ([beacon.proximity == CLProximityImmediate]) {
NSLog(#"Show");
[self.near setHidden: (YES)];
[self.far setHidden: (YES)];
[self.immediate setHidden: (NO)];
}
Heres the .h file
#interface TagDetailViewController : UIViewController
#property (nonatomic, strong) PFObject* TagDetail;
#property (strong, nonatomic)IBOutlet UILabel *tagname;
#property (nonatomic, strong)IBOutlet UIImageView *immediate;
#property (nonatomic, strong)IBOutlet UIImageView *near;
#property (nonatomic, strong)IBOutlet UIImageView *far;
#property (nonatomic, strong)IBOutlet UIButton *showOnMap;
#property CLLocationManager *locationManager;
#property CLBeaconRegion *rangedRegion;
#property NSUUID *artemisUUID;
#property CLBeaconMajorValue *major;
#property CLBeaconMinorValue *minor;
#property CLBeacon *proximity;
#end
Its telling me that the variable beacon is not identified, but doing so in the header file as *beacon doesn't remove any errors. What am I doing wrong? Im really new to this language so that is a large part of why Im running into errors, but I cant figure this one out.

You don't have a variable named beacon, you have a CLBeacon object named proximity.

Related

objective C making UITextField for vc1 become UILabel vc2

I am trying to get my UITextField email in my first view controller to become the UILabel in my next view controller. It says there is an error stating there is no visible #interface for NSString declares the selector initvalue. I thought the interface was being loaded from the vc1.h file when you imported it on the vc2? any help would be nice. Heres what I have so far:
vc1.h
#import <UIKit/UIKit.h>
#interface loginUserViewController : UIViewController
#property (nonatomic, retain, strong) IBOutlet UITextField *email;
#property (nonatomic, retain) IBOutlet UITextField *password;
#property (nonatomic, retain) IBOutlet UIButton *login;
#property (nonatomic,retain) IBOutlet UIButton *registerBtn;
-(IBAction)loginUser:(id)sender;
#end
vc2.h
#import <UIKit/UIKit.h>
#import "loginUserViewController.h"
#interface Home : UIViewController
#property (weak, nonatomic) IBOutlet UILabel *username;
#property (weak, nonatomic) IBOutlet UIBarButtonItem *Nav;
#property (weak, nonatomic) IBOutlet UIBarButtonItem *logout;
-(IBAction)logout:(id)sender;
-(IBAction)bandHome:(id)sender;
#end
vc2.m
import "Home.h"
#import "loginUserViewController.h"
#interface Home ()
#end
#implementation Home
#synthesize username, band1, band2, band3;
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if(self){
}
return self;
}
-(void)viewDidLoad
{
[super viewDidLoad];
loginUserViewController *object = [[loginUserViewController alloc]init];
NSString *string = [[NSString alloc] initWithFormat:#"%i",[object.email.text initValue]];
username.text = string;
}
vc1.m
#import "loginUserViewController.h"
#import "Home.h"
#import "createBandViewController.h"
#interface loginUserViewController ()
#end
#implementation loginUserViewController
#synthesize email, password;
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
}
- (void)viewDidload
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[self setEmail:nil];
[self setPassword:nil];
[super viewDidUnload];
}
-(IBAction)loginUser:(id)sender {
if ([email.text isEqualToString:#""] || [password.text isEqualToString:#""])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"alert" message:#"Please Fill all the field" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return;
}
Simply replace this string:
NSString *string = [[NSString alloc] initWithFormat:#"%i",[object.email.text initValue]];
with this string:
NSString *string = [[NSString alloc] initWithFormat:#"%i",[object.email.text intValue]];
and if you want simply the email just as a string then replace it with this string
NSString *string = [[NSString alloc] initWithFormat:#"%#",object.email.text];
your error will be resolved.Hope it helps :)
First of All in VC2.h
#import <UIKit/UIKit.h>
#import "loginUserViewController.h"
#interface Home : UIViewController
#property (strong, nonatomic) IBOutlet UILabel *username; // Keep property strong to get the value
in VC2.m
#synthesize username;
Now in VC1.h
#import <UIKit/UIKit.h>
#import "homeviewcontroller.h"
#interface loginUserViewController : UIViewController
#property (nonatomic, strong) IBOutlet UITextField *email;
#property (nonatomic, strong) IBOutlet UITextField *password;
#property (nonatomic) nsstring *username;
-(void)viewDidLoad
{
[super viewDidLoad];
username= self.email.text;
homeviewcontroller *object = [[homeviewcontroller alloc]init];
object.username.text=username;
}

Xcode use of undeclared identifier

I am new to coding and had some basic knowledge but i am building out my first app from a tutorial and have a issue i can't figure out and after a few days of looking figured i would just ask. I get an error in my implementation file when initializing the object in the view did load.
It says use of undeclared identifier. any help would be greatly appreciated.
Here is my view controller.m
#import "ViewController.h"
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSLog(#"titleLabel.text = %#", self.titleLabel.text);
self.bandObject = [[BandObject alloc] init];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
return YES;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
self.bandObject.name = self.nameTextField.text;
[self.nameTextField resignFirstResponder];
return YES;
}
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
self.bandObject.name =self.nameTextField.text;
[self saveBandObject];
[self.nameTextField resignFirstResponder];
return YES;
}
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
self.saveNotesButton.enabled = YES;
return YES;
}
-(BOOL)textViewShouldEndEditing:(UITextView *)textView
{
self.bandObject.notes = self.notesTextView.text;
[self.notesTextView resignFirstResponder];
self.saveNotesButton.enabled = NO;
return YES;
}
- (IBAction)saveNotesButtonTouched:(id)sender
{
[self textViewShouldEndEditing:self.notesTextView];
}
- (IBAction)ratingStepperValueChanged:(id)sender
{
self.ratingValueLabel.text = [NSString stringWithFormat:#"%g",self.ratingStepper.value];
self.bandObject.rating = (int)self.ratingStepper.value;
}
- (IBAction)tourStatusSegmentedControlValueChanged:(id)sender
{
self.bandObject.touringStatus = self.touringStatusSegmentedControl.selectedSegmentIndex;
}
- (IBAction)haveSeenLiveSwitchValueChanged:(id)sender
{
self.bandObject.haveSeenLive = self.haveSeenLiveSwitch.on;
}
#end
and here is my .h
#import <UIKit/UIKit.h>
#import "WBABand.h"
#interface ViewController : UIViewController <UITextFieldDelegate, UITextViewDelegate>
#property (nonatomic, strong) WBABand *bandObject;
#property (nonatomic, weak) IBOutlet UILabel *titleLabel;
#property (nonatomic, weak) IBOutlet UITextField *nameTextField;
#property (nonatomic, weak) IBOutlet UITextView *notesTextView;
#property (nonatomic, weak) IBOutlet UIButton *saveNotesButton;
#property (nonatomic, weak) IBOutlet UIStepper *ratingStepper;
#property (nonatomic, weak) IBOutlet UILabel *ratingValueLabel;
#property (nonatomic, weak) IBOutlet UISegmentedControl *touringStatusSegmentedControl;
#property (nonatomic, weak) IBOutlet UISwitch *haveSeenLiveSwitch;
- (IBAction)saveNotesButtonTouched:(id)sender;
- (IBAction)ratingStepperValueChanged:(id)sender;
- (IBAction)tourStatusSegmentedControlValueChanged:(id)sender;
- (IBAction)haveSeenLiveSwitchValueChanged:(id)sender;
#end
It is because you have an object in your .h called WBABand. And in your .m your are initializing a BandObject which does not exists.
Change this [[BandObject alloc] init];
to this [[WBABand alloc] init];
When you run into an issue, please try to narrow it down to the shortest code block possible to reproduce. At the very least, you should be pointing out the line that shows the error so that contributors can help you easier.
You are trying to instantiate an instance of BandObject, but the class you should be trying to instantiate is WBABand.
self.bandObject = [[WBABand alloc] init];

Can't Figure Out The Reason UILabel Isn't Displaying The String Being Assign to It - Quote Quiz App

I have been following online tutorials over at raywenderlich.com, and came upon a little road block. In a tutorial (Quote Quiz), I seem to have done something wrong because the strings, extracted from the Quote.plist, is simply not displaying on the question and answers labels.
Here is my view controller.h:
#import <UIKit/UIKit.h>
#class Quiz;
#interface ViewController : UIViewController
#property (nonatomic, assign) NSInteger quizIndex;
#property (nonatomic, strong) Quiz* quiz;
#property (nonatomic, weak) IBOutlet UILabel* questionLabel;
#property (nonatomic, weak) IBOutlet UILabel* answer1Label;
#property (nonatomic, weak) IBOutlet UILabel* answer2Label;
#property (nonatomic, weak) IBOutlet UILabel* answer3Label;
#property (nonatomic, weak) IBOutlet UIButton* answer1Button;
#property (nonatomic, weak) IBOutlet UIButton* answer2Button;
#property (nonatomic, weak) IBOutlet UIButton* answer3Button;
#property (nonatomic, weak) IBOutlet UIImageView* movie1;
#property (nonatomic, weak) IBOutlet UIImageView* movie2;
#property (nonatomic, weak) IBOutlet UIImageView* movie3;
#property (nonatomic, weak) IBOutlet UILabel* statusLabel;
#property (nonatomic, weak) IBOutlet UIButton* startButton;
#property (nonatomic, weak) IBOutlet UIButton* infoButton;
#end
.m
#import "ViewController.h"
#import "Quiz.h"
#interface ViewController ()
#property (nonatomic, assign) NSInteger answer;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.quizIndex = 999;
self.quiz = [[Quiz alloc] initWithQuiz:#"Quotes"];
self.questionLabel.backgroundColor = [UIColor colorWithRed:51/255.0 green:133/255.0 blue:238/255.0 alpha:1.0];
[self nextQuizItem];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void) nextQuizItem {
if(self.quizIndex == 999){
self.quizIndex = 0;
self.statusLabel.text = #"";
}else if((self.quiz.quizCount-1) > self.quizIndex) {
self.quizIndex++;
}else{
self.quizIndex = 0;
self.statusLabel.text = #"";
}
if(self.quiz.quizCount >= (self.quizIndex+1)){
self.questionLabel.text = self.quiz.quote;
self.answer1Label.text = self.quiz.ans1;
self.answer2Label.text = self.quiz.ans2;
self.answer3Label.text = self.quiz.ans3;
}else{
self.quizIndex = 0;
[self quizDone];
}
self.answer1Label.backgroundColor = [UIColor colorWithRed:51/255.0 green:133/255.0 blue:238/255.0 alpha:1.0];
self.answer2Label.backgroundColor = [UIColor colorWithRed:51/255.0 green:133/255.0 blue:238/255.0 alpha:1.0];
self.answer3Label.backgroundColor = [UIColor colorWithRed:51/255.0 green:133/255.0 blue:238/255.0 alpha:1.0];
self.answer1Button.hidden = NO;
self.answer2Button.hidden = NO;
self.answer3Button.hidden = NO;
}
-(void) quizDone {
}
#end
And my Quiz.h:
#import <Foundation/Foundation.h>
#interface Quiz : NSObject
#property (nonatomic, strong) NSMutableArray* movieArray;
#property (nonatomic, assign) NSInteger correctCount;
#property (nonatomic, assign) NSInteger incorrectCount;
#property (nonatomic, assign) NSInteger quizCount;
#property (nonatomic, readonly, strong) NSString* quote;
#property (nonatomic, readonly, strong) NSString* ans1;
#property (nonatomic, readonly, strong) NSString* ans2;
#property (nonatomic, readonly, strong) NSString* ans3;
-(id)initWithQuiz:(NSString*)plistName;
-(void)nextQuestion:(NSUInteger)idx;
-(BOOL)checkQuestion:(NSUInteger)question forAnswer:(NSUInteger)answer;
#end
and Quiz.m:
#import "Quiz.h"
#interface Quiz()
#property (nonatomic, strong) NSString* quote;
#property (nonatomic, strong) NSString* ans1;
#property (nonatomic, strong) NSString* ans2;
#property (nonatomic, strong) NSString* ans3;
#end
#implementation Quiz
-(id)initWithQuiz:(NSString *)plistName {
if((self=[super init])) {
NSString* plistCatPath = [[NSBundle mainBundle] pathForResource:plistName ofType:#"plist"];
self.movieArray = [NSMutableArray arrayWithContentsOfFile:plistCatPath];
self.quizCount = [self.movieArray count];
}
return self;
}
-(void)nextQuestion:(NSUInteger)idx {
self.quote = [NSString stringWithFormat:#"%#", self.movieArray[idx][#"quote"]];
self.ans1 = self.movieArray[idx][#"ans1"];
self.ans2 = self.movieArray[idx][#"ans2"];
self.ans3 = self.movieArray[idx][#"ans3"];
if(idx == 0){
self.correctCount = 0;
self.incorrectCount = 0;
}
}
-(BOOL)checkQuestion:(NSUInteger)question forAnswer:(NSUInteger)answer {
NSString* ans = [NSString stringWithFormat:#"%#", self.movieArray[question][#"answer"]];
if([ans intValue] == answer) {
self.correctCount++;
return YES;
}else{
self.incorrectCount++;
return NO;
}
}
#end
I am using the latest Xcode 6, the outlets are connected, and the plist file I am using has the name "Quotes.plist".
Any help or suggestion would be greatly appreciated.
Thank you.
You are not getting the next quiz question before displaying it.
Add the following to the second if statement of nextQuizItem in ViewController.m:
[self.quiz nextQuestion:self.quizIndex];
so that it looks like this
if(self.quiz.quizCount >= (self.quizIndex+1)){
[self.quiz nextQuestion:self.quizIndex]; // <-- ADD THIS
self.questionLabel.text = self.quiz.quote;
self.answer1Label.text = self.quiz.ans1;
self.answer2Label.text = self.quiz.ans2;
self.answer3Label.text = self.quiz.ans3;
}else{
self.quizIndex = 0;
[self quizDone];
}

UIView not updating in iPhone App

I am new to iPhone App development, below is ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self updateMyView];
}
- (IBAction)clickButtonResult:(id)sender
{
enteredText = [textField text]; // Or textField.text
NSLog(#"Number 1 : %i", number_1);
NSLog(#"Number 2 : %i", number_2);
NSLog(#"Entered Text is %#", enteredText);
int NUM_RESULT = number_1 + number_2;
verify_result = [NSString stringWithFormat:#"%i", NUM_RESULT];
NSLog(#"Verify Result : %#", verify_result);
NSString *final_result = [NSString stringWithFormat:#"%d", [enteredText isEqualToString:verify_result]];
int final_int_result = [final_result integerValue];
if (final_int_result) {
//result_label.text = #"Correct";
NSLog(#"Correct");
[self updateMyView];
} else {
//result_label.text = #"Wrong";
NSLog(#"Wrong");
}
}
- (int)getRandomNumberBetween:(int)min maxNumber:(int)max
{
return min + arc4random() % (max - min + 1);
}
- (void) updateMyView
{
number_1 = [self getRandomNumberBetween:10 maxNumber:99];
number_2 = [self getRandomNumberBetween:10 maxNumber:99];
num_1.text = [NSString stringWithFormat:#"%i", number_1];
num_2.text = [NSString stringWithFormat:#"%i", number_2];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
and ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
{
IBOutlet UILabel *num_1;
IBOutlet UILabel *num_2;
IBOutlet UILabel *result_label;
IBOutlet UITextField *textField;
int number_1;
int number_2;
NSString *verify_result;
NSString *enteredText;
BOOL display_result;
}
- (IBAction)clickButtonResult:(id)sender;
#end
After entering the correct result the UIView should be updated with updateMyView function but it is not happening.
Can anyone help here??
First of all, start using Properties.
ViewController.h
#interface ViewController : UIViewController
#property (nonatomic, weak) IBOutlet UILabel *num_1;
#property (nonatomic, weak) IBOutlet UILabel *num_2;
#property (nonatomic, weak) IBOutlet UILabel *resultLabel;
#property (nonatomic, weak) IBOutlet UITextField *textField;
#property (nonatomic) NSInteger number_1;
#property (nonatomic) NSInteger number_2;
#property (nonatomic, strong) NSString *verifyResult;
#property (nonatomic, strong) NSString *enteredText;
#property (nonatomic) BOOL displayResult;
- (IBAction)clickButtonResult:(id)sender;
#end
In ViewController.m code use self.{name of property}, for example self.textField for the textField property.
Now, go to Interface builder and connect the IBOutlet properties to the right objects. (click with right button on File's Owner)
Try changing num_1.text in viewDidLoad to make sure you have access to that label from your UIViewController.
So in viewDidLoad, just put something like
num1.text = #"Updated from viewDidLoad"
Make sure that you have connected num_1 and num_2 with the UILabels properly. It seems that you have not connected these.
Just move [self updateMyView]; outside the if statements in clickButtonResult: function
then it will update the view when click the button.
if (final_int_result) {
//result_label.text = #"Correct";
NSLog(#"Correct");
} else {
//result_label.text = #"Wrong";
NSLog(#"Wrong");
}
[self updateMyView];

scroll view isn't scrolling when compiled

I have the following app that I've implemented a scroll view (image outlines hierarchy on storyboard:e
I have turned off Auto Layout, as severe posts here seem to indicate this creates a problem.
here is my .h file:
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
#import <AssetsLibrary/ALAsset.h>
#import <AssetsLibrary/ALAssetRepresentation.h>
#import <ImageIO/CGImageSource.h>
#import <ImageIO/CGImageProperties.h>
#import <CoreLocation/CoreLocation.h>
#interface DobInAHoonViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate, MFMailComposeViewControllerDelegate, UITextFieldDelegate, CLLocationManagerDelegate>
{
IBOutlet UIPickerView *vehiclePickerView;
UIImagePickerController *picker1;
UIImagePickerController *picker2;
UIImage *image;
IBOutlet UIImageView *imageView;
CLLocationManager *locationManager;
CGFloat animatedDistance;
}
#property (strong, nonatomic) IBOutlet UIImageView *BackgroundImage;
#property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
#property (strong, nonatomic) NSString *Latitude;
#property (strong, nonatomic) NSString *longditute;
#property (strong, nonatomic) NSArray *toRecipients;
#property (strong, nonatomic) ALAssetsLibrary *assetsLibrary;
#property (strong, nonatomic) NSMutableArray *groups;
#property (nonatomic, retain) IBOutlet UITextField *vehilceMake;
#property (nonatomic, retain) IBOutlet UITextField *vehilceColour;
#property (nonatomic, retain) IBOutlet UITextField *regoNumber;
#property (nonatomic, retain) IBOutlet UITextField *location;
#property (nonatomic, retain) IBOutlet UITextField *additionalInfo;
#property (nonatomic, retain) IBOutlet UITextField *vehicleType;
- (IBAction)takePhoto;
-(IBAction)chooseExisting;
-(IBAction)actionEmailComposer;
-(IBAction)textFileReturn:(id)sender;
-(IBAction)DismissKeyboard:(id)sender;
#end
and my .m file:
#import "DobInAHoonViewController.h"
#interface DobInAHoonViewController ()
#end
#implementation DobInAHoonViewController
#synthesize BackgroundImage;
#synthesize vehilceColour;
#synthesize vehilceMake;
#synthesize regoNumber;
#synthesize Latitude;
#synthesize location;
#synthesize longditute;
#synthesize additionalInfo;
#synthesize toRecipients;
#synthesize assetsLibrary;
#synthesize groups;
#synthesize vehicleType;
#synthesize scrollView;
static const CGFloat KEYBOARD_ANIMATION_DURATION = 0.3;
static const CGFloat MINIMUM_SCROLL_FRACTION = 0.2;
static const CGFloat MAXIMUM_SCROLLFRACTION = 0.8;
static const CGFloat PORTRAIT_KEYBOARD_HEIGHT = 216;
static const CGFloat LANDSCAPE_KEYBOARD_HEIGHT = 140;
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[vehilceMake resignFirstResponder];
[vehilceMake resignFirstResponder];
[vehilceColour resignFirstResponder];
[location resignFirstResponder];
[additionalInfo resignFirstResponder];
[regoNumber resignFirstResponder];
return YES;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.scrollView setScrollEnabled:YES];
[self.scrollView setContentSize:(CGSizeMake(320, 1000))];
locationManager = [[CLLocationManager alloc]init];
toRecipients = [[NSArray alloc]initWithObjects:#"scott.boon#shellharbour.nsw.gov.au", nil];
BackgroundImage.alpha = 0.3;
static int emergAlertCounter;
if (emergAlertCounter <1) {
UIAlertView *emergencyAlert = [[UIAlertView alloc]
initWithTitle:#"NOTE" message:#"Do not endanger your life to dob in a hoon. If your life is threatened, or you are reporting an emergency situation, exit this app and dial '000' IMMEDIATLY!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[emergencyAlert show];
emergAlertCounter = emergAlertCounter+1;
}
}
for some reason, when i run the app, the scroll view is not scrolling. I have set the property to scroll in the interface builder.
Any suggestions would be greatly appreciated.
You'll have to make sure your scroll view is smaller than 320 x 1000 and that the embedded view is larger than 320 x 1000

Resources