Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-29-2009, 11:11 PM   #1 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 2
gathius is on a distinguished road
Question initWithNibName inits UILabel to 0x0?

Hi,

I'm running into a situation where I am initializing a view controller from a nib file and it doesn't seem to properly initialize the UILabel in the nib. I have an IBOutlet UILabel instance variable in my view controller, and after the call to initWithNibName, it comes back with 0x0. The outlet is connected to the UILabel in the nib file in Interface Builder.

Here's my code:

view controller gets initialized during row click of nav controller:

Code:
QuestionViewController *nextController = [[QuestionViewController alloc] 
 initWithQuestion:nextQuestion];
Here's the code for initWithQuestion:

Code:
	if (self = [super initWithNibName:@"QuestionView" bundle:nil])
	{
		self.myQuestion = initQuestion;
		
		questionTextLabel.text = initQuestion.questionTextString;
		[self.questionTextLabel retain];
	}
	
	return self;
so when I'm stepping through, after the line "self.myQuestion = initQuestion", the myQuestion property shows up as having a valid address (0x1234 or something)

but the questionTextLabel property shows up as having address of 0x0. So when I try to set its text, nothing happens.

I've declared questionTextLabel in the header file for this view controller with the following statements:

Code:
IBOutlet UILabel			*questionTextLabel;
...
@property (nonatomic, retain) IBOutlet UILabel	 *questionTextLabel;
It was my understanding that the call to initWithNibName should initialize a UILabel object and set my local UILabel pointer to point to that object. Why is this not happening?

Thanks for the help! Let me know if I need to post any more code.
gathius is offline   Reply With Quote
Old 04-30-2009, 01:00 AM   #2 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 2
gathius is on a distinguished road
Default

I figured it out.

The view controller's UILabel pointer apparently doesn't get set to the UILabel object created during initWithNibName until AFTER the view has been loaded and goes on screen.

That's a conjecture anyways. There is maybe some intermediate place that it happens.

Short answer is that I simply moved the place that I set my label's text to the custom string into the "viewDidLoad" method and it worked swimmingly.
gathius is offline   Reply With Quote
Old 03-12-2010, 01:00 PM   #3 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 13
chucky is on a distinguished road
Default

Can you provide a reference that says the initWithNibName initializes the UILabel object?
Does it allocate it as well?
chucky is offline   Reply With Quote
Old 03-12-2010, 07:20 PM   #4 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

Quote:
Originally Posted by chucky View Post
Can you provide a reference that says the initWithNibName initializes the UILabel object?
Does it allocate it as well?
You won't find such a reference because in general it doesn't. In my own code I've found it is initialized anytime I try to access the view associated with the view controller.
JasonR is offline   Reply With Quote
Reply

Bookmarks

Tags
iboutlet, initwithnibname, interface builder, uilabel

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 307
7 members and 300 guests
blueorb, givensur, guusleijsten, jbro, mer10, n00b, SLIC
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,880
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:03 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0