#import "CLSViewController.h"
@implementation CLSViewController
@synthesize statusText = _statusText;
- (void)viewDidUnload {
[self setStatusText:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (IBAction)buttonPressed:(UIButton *)sender {
NSString *title = [sender titleForState:UIControlStateNormal];
-> statusText.text = [NSString stringWithFormat:@"%@ button pressed.", title];
}
@end
The line that says statusText.text = …
Did I not synthesize it correctly? Removing the = _statusText; from it gets rid of the error, but I thought we were supposed to set it to something.
if you want to access the property, you should use
you can also access the variable directly using _statusText:
If you remove _statusText from the synthesize line, the instance variable name will be assumed to be “statusText”, so that is why your situation works when you remove it.
IMO you should always access it as a property (e.g. self.statusText) except in init/dealloc since you are declaring it as such.