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

wordgeist

macrumors newbie
Original poster
Jun 15, 2009
1
0
I'm setting a UILabel but is returning null.

.h file:

Code:
@property (retain,nonatomic) UILabel *label;

.m file :

Code:
@synthesize label;

- (void)viewDidLoad
{
    self.label.text=@"some text";
 [super viewDidLoad];
}

I check the value of label and is null. Can any body tell me why is null? Can anybody tellme what I'm doing wrong?
 
Last edited by a moderator:
I'm setting a UILabel but is returning null.

.h file:

Code:
@property (retain,nonatomic) UILabel *label;

.m file :

Code:
@synthesize label;

- (void)viewDidLoad
{
    self.label.text=@"some text";
 [super viewDidLoad];
}

I check the value of label and is null. Can any body tell me why is null? Can anybody tellme what I'm doing wrong?

Defining and synthesizing a property does not create the object the property points to. That just creates an instance variable and the getter/setter methods for the property. The instance variable starts off containing nil. You have to create an object and save it in the property or it will stay nil.

Usually with views, you define your property or instance variable as an IBOutlet and connect it to an object in Interface Builder. Then when you load the XIB file or storyboard, the system instantiates a view and saves a pointer to it in your outlet.

You can also create the view object manually and save a pointer to it in your property, but I don't recommend that. Creating views manually is more work, and it also makes for code that's harder to maintain. If you want to rearrange your view layout, you have to change code. Better to define your views in an XIB or storyboard.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.