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 02-20-2011, 08:15 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 122
architectpianist is on a distinguished road
Question UILabel text property returns null

Hi,
I'm trying to change a UILabel's text on the event touchesEnded.
Here's my code:
Code:
- (void) setInstructions:(NSString *)text
{
	[instructions performSelectorOnMainThread:@selector(setText:) withObject:text waitUntilDone:YES];
}
...
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
	NSLog(@"Touches ended");
	
	UITouch *touch = [touches anyObject];
	touchPoint = [touch locationInView:self];
	originalPoint = touchPoint;
	[self setInstructions:@"Next step reached."];
	drawingState++;
	fprintf(stderr, "%s", instructions.text);
	
	[location removeFromSuperview];
	location = nil;
}
A previous call to setInstructions: (from initWithFrame:) returns the correct display text, but when I call it from touchesEnded, it doesn't do anything to the UILabel. The log says:
Code:
2011-02-20 20:00:24.823 MyProject[62997:207] Touches ended
(null)
Why is the instructions' text property returning null? And how can I update the UILabel's text?
Thanks!
architectpianist is offline   Reply With Quote
Old 02-20-2011, 08:31 PM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Because label.text is not c string, so %s will not print it.

Try this instead:

NSLog(@"label is:%@ text is: %@", instructions, instructions.text);

Also, I doubt the performSelectorOnMainThread is required. UIKit only calls touchesEnded:withEvent: on the main thread so we're already there, right?
__________________

Free Games!

Last edited by smasher; 02-20-2011 at 08:33 PM.
smasher is offline   Reply With Quote
Old 02-20-2011, 09:50 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 122
architectpianist is on a distinguished road
Default

Following what smasher said, and I got:
Code:
2011-02-20 21:38:26.640 Trying[63792:207] Label is: (null) text is: (null)
Thanks anyway, but who knows what's wrong with this?
architectpianist is offline   Reply With Quote
Old 02-20-2011, 10:27 PM   #4 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

What the output from smahser's NSLog tells you is that your label doesn't exist, that is the pointer points to nothing.
baja_yu is offline   Reply With Quote
Old 02-20-2011, 11:20 PM   #5 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Yep, it looks like you forgot to hook up that outlet in interface builder, or failed to point that pointer at a valid label.
__________________

Free Games!
smasher is offline   Reply With Quote
Reply

Bookmarks

Tags
null, touchesended, uilabel, update

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: 378
14 members and 364 guests
cpsclicker, dre, Error404, Gaz, gmarro, jeroenkeij, Kirkout, mottdog, Music Man, PavelMik, teebee74, whitey99, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,666
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, cpsclicker
Powered by vBadvanced CMPS v3.1.0

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