我已經搜索了高和低的答案我的困境,我相信這是由於我適應ARC的困難 - 我希望能部署我的應用程序在iOS5上,我目前正在測試它在beta4 3GS上。iOS - UILabel變量變爲(null)
當的viewController被加載(viewDidLoad中:)我的應用程序的alloc init的一個UILabel和customises並將它添加到屏幕的頂部:
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現在(空)。我看不出爲什麼該屬性已被釋放 - 它在頭文件中設置了一個非原子的強屬性,並在.m文件的頂部合成。
也許我還應該補充說,一旦應用程序成功加載,我已經分配給IBIutlet的UIImageView的非原子性強屬性也會一次顯示專輯封面(即,這不會作爲子視圖添加) 。
任何幫助將不勝感激:D
這可能與iOS5無關,所以我在評論。看到財產聲明將有所幫助。我懷疑valueForProperty調用返回零。在另一個筆記,self._artistString只是讀錯了(不應該是一個下劃線),我期望self.artistLabel = [[UILabel alloc] ...超過了保留。 – InsertWittyName