类值AVPlayerItem被释放,而键值观察者仍然在其中注册

时间:2016-06-14 05:23:40

标签: ios objective-c iphone nsarray

MyCustomView.m

{
   -(IBAction)buttonPlay{
      `Add observer for AVPlayer`
      }
    -(void)dealloc{
      `Remove Observer for AVPlayer`
     }

}

MYViewController.m

{
   for (i=0;i<10;i++){
         myCustomView *m = [[myCustomView alloc]init];
         [arrlist addobject:m];
       }

   -(void)reset{
       [arrList remove allObjects]; //**Crash the app**
     }
}

如何从数组中删除对象。 我已经在dealloc方法中删除了观察者,但它仍然没有工作......

感谢您宝贵的时间

1 个答案:

答案 0 :(得分:0)

dealloc不会在ARC环境中调用。而不是像下面那样放置通知观察者

[[NSNotificationCenter defaultCenter] addObserver:self
                                                  selector:@selector(playerItemDidReachEnd:)
                                                      name:AVPlayerItemDidPlayToEndTimeNotification
                                                    object:self.playerItem];