Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Kapthehat

macrumors member
Original poster
Jul 1, 2013
51
0
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
 
Last edited by a moderator:
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

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.
 
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
 
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

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?
 
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?

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.
 
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.

Makes sense. I forgot the .nib loads and stores it's object's into archive.

Thanks.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.