IOS KVO没有在delloc中移除导致奔溃

1.背景

   为了监听tableview的移动

           [_tableView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];
2.问题

  奔溃报错Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior

3.解决

   - (void)dealloc
   {
       [_tableView removeObserver:self forKeyPath:@"contentOffset" context:nil];
   }

猜你喜欢

转载自www.cnblogs.com/xiyangxixia/p/10336887.html