正如我的對象中聲明的對象:除去觀察者的dealloc與
AVQueuePlayer *queuePlayer;
在代碼我已經添加的觀察者:
- (void) playStreamedTrack: (Track *) track {
[queuePlayer addObserver:self forKeyPath:@"status" options:0 context:nil];
[queuePlayer addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(1, NSEC_PER_SEC)
queue:nil
usingBlock:^(CMTime time) {
progress = time.value/time.timescale;
}];
}
我試圖除去觀察者跟隨,但不工作
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[queuePlayer removeObserver:self forKeyPath:@"status" context:nil];
}
我該如何刪除觀察者?
是否調用了'dealloc'? – trojanfoe 2014-09-22 07:09:21
是的,我使用的dealloc方法在上面。 控制檯中的錯誤是: ***由於未捕獲的異常'NSInternalInconsistencyException'而終止應用程序,原因:'類AVQueuePlayer的實例0x7f970b55ae00被解除分配,而鍵值觀察者仍在註冊它。現有的觀測信息:( 的語境:爲0x0,物業:0x7f970b6fb390> )」 –
2014-09-22 07:39:26
觀察員註冊了多少次?它看起來像是在錯誤的地方註冊,如果這個「軌道」不止一次播放。 – trojanfoe 2014-09-22 07:41:58