Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios observeValueForKeyPath:发送到解除分配实例的消息_Ios_Objective C_Automatic Ref Counting_Nsnotificationcenter - Fatal编程技术网

Ios observeValueForKeyPath:发送到解除分配实例的消息

Ios observeValueForKeyPath:发送到解除分配实例的消息,ios,objective-c,automatic-ref-counting,nsnotificationcenter,Ios,Objective C,Automatic Ref Counting,Nsnotificationcenter,我有一个简单的UIView孩子,我很困惑为什么会出现这个错误(导致应用程序崩溃): [VideoView observeValueForKeyPath:of对象:更改:上下文:]:消息发送到解除分配的实例0x13009b670 以下是VideoView课程: @implementation VideoView - (id)init { self = [super init]; if (self) { [[NSNotificationCenter defaultC

我有一个简单的UIView孩子,我很困惑为什么会出现这个错误(导致应用程序崩溃):

[VideoView observeValueForKeyPath:of对象:更改:上下文:]:消息发送到解除分配的实例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启用

你把事情搞混了。该错误不是由
NSNotificationCenter
通知引起的。在您正在使用的代码中的某个地方,当对象被解除分配时,您没有删除该观察者,这就是发生崩溃的原因。

您将事情搞混了。该错误不是由
NSNotificationCenter
通知引起的。在您正在使用的代码中的某个地方,当对象被解除分配时,您不会删除该观察者,这就是发生崩溃的原因。

Ahh正确,添加
[self.player removeObserver:self forKeyPath:@“currentItem.status”]解决了问题。但必须注意例外情况:啊,对,添加
[self.player removeObserver:self forKeyPath:@“currentItem.status”]解决了问题。但必须小心例外情况: