views:

220

answers:

2

Hi, I'm having an issue with an iPhone app I'm working on.

It uses a separate class called Radio which streams a station in. When the title of the stream is updated, it calls back to RadioViewController with the method updateTitle:

- (void)updateTitle:(NSString *)newTitle
{
    NSLog(@"update title called with title: %@", newTitle);
    [self.nowPlaying setText:newTitle];
}

For some reason, I can't seem to get nowPlaying to update. If I call setText from viewDidLoad, then it works fine.

Also, with any sort of user interaction, whether a button or something else, the text changes fine, as in:

- (IBAction)playButton:(id)sender
{
[self.nowPlaying setText:@"now playing test"];
}

nowPlaying is linked up in the XIB and setup as such:

    IBOutlet UILabel  *nowPlaying;
@property(nonatomic, retain) UILabel *nowPlaying;

And updateTitle is setup as

- (void)updateTitle:(NSString *)title;

The code builds and runs fine, without error. But the UILabel is just not changing.

A: 

After you set the title, NSLog the self.nowPlaying.title to make sure it's changed.

You may need an explicit [self.nowPlaying setNeedsDisplay]; to force an update.

If not, do the normal debugging to make sure that self.nowPlaying is a real object, etc. Are you sure nowPlaying is connected to the right label in IB?

Kailoa Kadano
Looks like self.nowPlaying was nil. Apparently I was creating another instance of it instead of using the current instance so the UILabel was never created.Thanks for mentioning that!
Conor B
A: 

Try editing your updateTitle method as follows:

NSLog(@"Update title will update %@ with %@", self.nowPlaying, newTitle);
[self.nowPlaying performSelectorOnMainThread:@selector(setText:) withObject:newTitle waitUntilDone:NO];

I have a feeling you are updating the title on a background thread which is not supported in many use cases.

Jason