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

Posted IOS少年

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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];
   }

 





以上是关于IOS KVO没有在delloc中移除导致奔溃的主要内容,如果未能解决你的问题,请参考以下文章