I'm starting to learn how iOS is evolving in a minute, and I currently have an IOS6 book starting with Apress, which I am working with.
Chapter 2 has a simple tutorial showing two buttons and a shortcut, and when a button is pressed, it appears on the label that it pressed.
I finished the tutorial, but he raised one question that I cannot find the answer to.
The tutorial uses ARC (automatic reference counting), if that matters.
Here is the code
Header file:
And file m:
#import "MTMViewController.h" @implementation MTMViewController - (IBAction)buttonPressed:(UIButton *)sender { NSString *title = [sender titleForState:UIControlStateNormal]; NSString *plainText = [NSString stringWithFormat:@"%@ button pressed.", title]; statusLabel.text = plainText; } @end
The above describes how it appears in the book, however, when I ran the tutorial in Xcode, I could not compile the following line:
statusLabel.text = plainText;
And instead, I had to change it to:
_statusLabel.text = plainText;
When I did this, the code compiled and worked fine, I tried to find out why this happened, returning to the tutorial to find out if I missed something, but did not see anything.
Can someone explain why the code in the book did not compile and why I had to add an underscore to the front of the variable? Is this right or did I do something wrong?
Donal rafferty
source share