开发者

iOS - UILabel variable becoming (null)

I have searched high and low for an answer to my predicament and I believe it is due to my difficulty in adapting to ARC - I am hoping to deploy my app on iOS5 and am currently testing it in on a beta4 3GS.

When the开发者_如何学编程 viewController is loaded (viewDidLoad:) my app alloc init's a UILabel and customises it to add it to the top of the screen:

UIView *navHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 44)];
self.artistLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 2, 280, 15)];
artistLabel.font = [UIFont systemFontOfSize:12];
artistLabel.textColor = [UIColor grayColor];
artistLabel.backgroundColor = [UIColor clearColor];
artistLabel.textAlignment = UITextAlignmentCenter;
[navHeaderView addSubview:artistLabel];

self.navigationBar.topItem.titleView = navHeaderView;

Okay, this works fine and fills in the relevant detail by accessing a updateTrack method:

- (void)updateTrack 
{
    _player = [MPMusicPlayerController iPodMusicPlayer];
    _item = [_player nowPlayingItem];

    self._artistString = [_item valueForProperty:MPMediaItemPropertyArtist];

    self.artistLabel.text = self._artistString;
}

This method is called when the music playing is changed using NSNotifications. However the artistString UILabel is now (null). I cannot see why the property has been released - it is set a nonatomic, strong property in the header file and synthesized at the top of the .m file.

Maybe I should also add that a nonatomic, strong property I have assigned to an IBOutlet of UIImageView also goes (null) once the app has successfully loaded, displayed the album art once (i.e. this is not added as a subview).

Any help would be greatly appreciated :D


I figured out that my issue was not the ARC on the variables I was using. Instead it was the notifications setup in the App Delegate that were not communicating correctly with the IBOutlets / ViewController's UILabels. Sorry to be a pain everyone.


This has nothing to do with being a beta iOS.

In your header are you defining the UILabel as well as using @property / @synthesize?

Also, remove the self. from the label.


iOS5 is still under NDA. If you are a registered developer, please ask this question in the beta Apple forums.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜