Writing value to UILabel

Discussion in 'iOS Programming' started by Kapthehat, Jul 19, 2013.

  1. Kapthehat, Jul 19, 2013
    Last edited by a moderator: Jul 19, 2013

    Kapthehat macrumors member

    Joined:
    Jul 1, 2013
    #1
    hello I am new to xcode and working through the beginning IOS develppment book by Apress. I am getting stuck on an example in chapter 3 - handling user interaction.

    Code:
    - (IBAction)buttonPressed:(UIButton *)sender {
        NSString *title = [sender titleForState:UIControlStateNormal];
        NSString *plainText = [NSString stringWithFormat:@"%@ button pressed.",title ];
        _statusLabel.text= plainText;
    }
    
    The code is supposed to write a value to the screen when a button is pressed. However I get an error stating " 'property 'text' not found on object type NSconstraint". thanks

    regards

    Kaps
     
  2. Tander macrumors 6502a

    Tander

    Joined:
    Oct 21, 2011
    Location:
    Johannesburg, South Africa
    #2
    Can you post your .h and .m files complete for us?

    Looking at the above code - syntactically, it's correct - so this is why I need to see the rest of the code.
     
  3. dantastic macrumors 6502

    dantastic

    Joined:
    Jan 21, 2011
    #3
    The statusLabel IBOutlet isn't connected to the label I don't think.
     
  4. Kapthehat thread starter macrumors member

    Joined:
    Jul 1, 2013
    #4
    Sure :-

    Code:
    //  BIDViewController.m
    //  button press kk1
    //
    //  Created by Kapil Kapur on 19/07/2013.
    //  Copyright (c) 2013 Apress. All rights reserved.
    //
    
    #import "BIDViewController.h"
    
    @interface BIDViewController ()
    
    @end
    
    @implementation BIDViewController
    
    
    - (IBAction)buttonPressed:(UIButton *)sender {
        NSString *title = [sender titleForState:UIControlStateNormal];
        NSString *plainText = [NSString stringWithFormat:@"%@ button pressed.",title ];
        _statusLabel.text= plainText;
    }
    @end
    
    

    and:-

    Code:
    //  BIDViewController.m
    //  button press kk1
    //
    //  Created by Kapil Kapur on 19/07/2013.
    //  Copyright (c) 2013 Apress. All rights reserved.
    //
    
    #import "BIDViewController.h"
    
    
    @interface BIDViewController ()
    
    @end
    
    @implementation BIDViewController
    
    
    - (IBAction)buttonPressed:(UIButton *)sender {
        NSString *title = [sender titleForState:UIControlStateNormal];
        NSString *plainText = [NSString stringWithFormat:@"%@ button pressed.",title ];
        _statusLabel.text= plainText;
    }
    @end
    
    
     
  5. Tander macrumors 6502a

    Tander

    Joined:
    Oct 21, 2011
    Location:
    Johannesburg, South Africa
    #5
    You quote the same file twice. :)

    @ dantastic - I'm not sure that would cause an error? You would just get a UI that doesn't update the label?
     
  6. dantastic macrumors 6502

    dantastic

    Joined:
    Jan 21, 2011
    #6
    Code:
    _statusLabel.text= plainText;
    You think that _statusLabel is a UILabel. And it is in the header file but you actually "create" the backing object in the nib. Your outlet is connected to an object of the type NSConstraint.

    This will not cause an error (and it dosn't). It's perfectly legit (as such.). The problem is that NSConstraint does not have a "text" property.
     
  7. Tander macrumors 6502a

    Tander

    Joined:
    Oct 21, 2011
    Location:
    Johannesburg, South Africa
    #7
    Makes sense. I forgot the .nib loads and stores it's object's into archive.

    Thanks.
     

Share This Page