简体   繁体   English

KVO意外崩溃

[英]KVO Unexpected Crash

I have a UITableView whose height changes at runtime : the app loads images and then displays them in the TableView. 我有一个UITableView,其高度在运行时更改:应用程序加载图像,然后在TableView中显示它们。 I've implemented a pull to refresh like feature for the footer of my tableview. 我已经为我的tableview的页脚实现了一个刷新功能。

Since height of the rows is not constant, I have added an observer on my UITableView: 由于行的高度不是常量,我在UITableView上添加了一个观察者:

[self.tableView addObserver:_refreshFooter
                 forKeyPath:@"contentSize"
                    options:NSKeyValueObservingOptionNew
                    context:NULL];

In my _refreshFooter , the following method is called as soon as the contentSize changes : 在我的_refreshFooter中 ,只要contentSize发生更改,就会调用以下方法:

- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context
{
  UITableView *tbV = object;

  float realBottom = MAX(tbV.frame.size.height, tbV.contentSize.height);
  self.frame = CGRectMake(self.frame.origin.x,
                          realBottom,
                          self.frame.size.width,
                          self.frame.size.height);
}

The app is basically a tabbar app where each tab is an instance of the TableViewController. 该应用程序基本上是一个tabbar应用程序,其中每个选项卡是TableViewController的一个实例。 On our iPhone 4 and 4S in 5.0.1 and 5.1, we have never experienced any crashes due to KVO but our users tells us unexpected behaviour such as the footer not being moved or crash. 在5.0.1和5.1版本的iPhone 4和4S上,由于KVO,我们从未遇到任何崩溃,但是我们的用户告诉我们意外的行为,例如页脚没有被移动或崩溃。

The crash experienced is the following : 遇到的崩溃如下:

0   libobjc.A.dylib 0x3671bf78 objc_msgSend + 15
1   Foundation 0x31145659 NSKeyValuePushPendingNotificationPerThread + 68
2   Foundation 0x3113774b NSKeyValueWillChange + 414
3   Foundation 0x3110e84f -[NSObject(NSKeyValueObserverNotification) willChangeValueForKey:] + 182
4   Foundation 0x31190b23 _NSSetSizeValueAndNotify + 82
5   UIKit 0x32368f8d -[UITableView(_UITableViewPrivate) _updateContentSize] + 572
6   UIKit 0x3249cd51 -[UITableView setTableFooterView:] + 432

viewWillDisapper释放NSKeyValueObservingOptionNew并添加它是viewWillAppear

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM