Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Code and run issue on chapter 3

I have tried the code from chapter 3 several times to no avail.

When I put in statusLabel.text = plainText;  Xcode keeps telling me I need to type _statusLabel.text instead.

When I run the code the app crashes there every time.

I also tried the NSAttributedString code as well and ran into the same problem.

Not sure what I am doing wrong.

Comments

  • Figured out what was going on. Still needed the _statusLabel.text but it works once I disconnect the phone from Xcode. On to bigger and better things! :)
  • Oops, that is a serious typo in the book, that was even pointed out by our tech reviewer, but somehow slipped through the cracks anyway! :O

    This will be the first known item in the errata list for this edition. :(

    //jack
  • edited January 2013
    I had the same issue but I used self instead of the underscore as pointed out by sleightofhand, it works either way.

    Changed

    statusLabel.text =  plainText;

    to

    self.statusLabel.text =  plainText;

  • I've got the Kindle version of the book displaying on my iPad. Some of the text displays... strangely?

    Can someone tell if my code is correct?  I keep receiving errors.

    @implementation BIDViewController

    - (IBAction)buttonPressed:(UIButton *)sender {

        NSString *title = [sender titleForState:(UIControlState)];

        NSString *plainText = [NSString stringWithFormat:@ "%@ button pressed.", title];

        self.statusLabel.text = plainText;

    }

    @end



    Thanks

  • Strange! The line that you've highlighted in red should look like this instead:

        NSString *title = [sender titleForState:UIControlStateNormal];


    If your Kindle version is showing something else, please verify it for me and I will try to pass the info on to the right place, if I can.

    //jack
  • Why do you need the _ (or self.) when referring to the statusText outlet?  Why can't you just use statusText?
  • edited January 2013
    @ktreanor Xcode has the functionality of automatically generating an @Synthesize once you create an @Protocol in the interface file for you're instant variables. therefore there is no need to type in the @Synthesize in the implementation file. However, the code generated Xcode and which you can't see is (in the case of this exercise):
    @Synthesize statusText=_statusText;
    therefore you use _statusText to access the instant variable. 
    if you want to use statusText without the underscore, just retype @synthesize in your .m file as :
    @Synthesize statusText;

  • I have read on a few websites that the recommended method to access a property is to use the self (i.e self.statusText.text = plainText).  This way you are using the autosynthesized setters and getters.  I am curious why the authors chose to use _statusText instead of self.statusText? Is this just personal preference?
Sign In or Register to comment.