iOS - UILabel变量变为(null)



我一直在寻找我的困境的答案,我相信这是由于我难以适应ARC -我希望在iOS5上部署我的应用程序,目前正在测试它在beta版3GS上。

当viewController被加载(viewDidLoad:)时,我的app alloc init's a UILabel并自定义它以将其添加到屏幕的顶部:

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;

好的,这工作得很好,并通过访问updateTrack方法填充相关细节:

- (void)updateTrack 
{
    _player = [MPMusicPlayerController iPodMusicPlayer];
    _item = [_player nowPlayingItem];
    self._artistString = [_item valueForProperty:MPMediaItemPropertyArtist];
    self.artistLabel.text = self._artistString;
}

这个方法在使用NSNotifications改变音乐播放时被调用。然而,artistString UILabel现在是(null)。我不明白为什么这个属性被释放了——它在头文件中被设置为一个非原子的强属性,并在.m文件的顶部合成。

也许我还应该添加一个非原子的,强属性我已经分配给UIImageView的IBOutlet也去(null)一旦应用程序已经成功加载,显示相册封面一次(即这不是添加为子视图)。

D

我发现我的问题不在于我所使用的变量的ARC。相反,是App Delegate中的通知设置没有正确地与IBOutlets/ViewController的uilabel进行通信。很抱歉给大家添麻烦了

这与测试版iOS无关。

在您的标题中,您是否定义了UILabel以及使用@property/@synthesize ?

同时,从标签中删除self.

iOS5仍处于保密协议下。如果您是注册开发者,请在Apple测试版论坛中询问此问题。

最新更新