类 AVPlayerItem 被解除分配,而键值观察器仍在向其注册



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 方法中删除了观察器,但它仍然不起作用......

感谢您的宝贵时间

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

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

最新更新