I have a UITableView whose height changes at runtime: an application loads images and then displays them in a TableView. I applied pull to update as a function for the footer of my table view.
Since the row height is not constant, I added an observer to my 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:
- (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);
}
, TableViewController.
iPhone 4 4S 5.0.1 5.1 - KVO, , , .
:
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