I just got to start developing for ios 6 on xcode. But as a novice developer, i have come into a problem. Following the guide in the book 'beginning ios5 development: exploring the ios sdk' on chapter 3, the 'Button fun' example.
I am having problems with the identifier 'statusText' which i have already declared in the .h code.
Here's my code so far, any help would be highly appreciated. thank you in advance.
my BIDViewController.h is like so
#import <UIKit/UIKit.h>
@interface BIDViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *
statusText;
- (IBAction)buttonPress:(UIButton *)sender;
@end`
and my BIDViewController.m is like so
#import "BIDViewController.h"
@interface BIDViewController ()
@end
@implementation BIDViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)buttonPress:(UIButton *)sender {
NSString *title = [sender titleForState:<#(UIControlState)#>];
statusText.text = [NSString stringWithFormat:@"%@ button pressed.", title];
}
@end
i have followed the book but can't seem to understand why this occurs, pls help.
Well, for starters, this should be only one line
@property (weak, nonatomic) IBOutlet UILabel *statusText;
Now, when you declare a property, you don't get a variable named like that unless you synthesize it like this:
@implementation Class
@synthesize propertyName;
@end
That's why statusText doesn't exist.
You have three options:
statusText
like that so you can use that ivar.self.statusText
._statusText
, access it like that to access the variable directly.You can also use a combination of 2 and 3