0
私は簡単なのUIViewの子供を持っていると私は私が(アプリがクラッシュした)このエラーを取得しています理由としては非常に混乱しています:observeValueForKeyPath:割り当て解除インスタンスに送信されたメッセージ
ここ[VideoView observeValueForKeyPath:ofObject:change:context:]: message sent to deallocated instance 0x13009b670
VideoView
クラスは次のとおりです。
@implementation VideoView
- (id)init {
self = [super init];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(stopVideo)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
}
return self;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
//.. stopVideo method
@end
私dealloc
通知が割り当て解除インスタンスに送信されることはありませんことを保証しませんか?それ以外にどうすれば起こるのを防ぐことができますか?
iOS 9、ARC対応
Ahhは、[self.player removeObserver:self forKeyPath:@ "currentItem.status"];を追加して問題を解決しました。しかし、例外については注意が必要:http://stackoverflow.com/questions/1582383/how-can-i-tell-if-an-object-has-a-key-value-observer-attached – Cbas