There are one to three UITableViewCells in a UITableViewView. Is there a way to always position the cell(s) at the bottom of screen after rel
The best way of doing this I found is to observe the content size of the tableview and adjust the inset if necessary. For example:
static char kvoTableContentSizeContext = 0;
- (void) viewWillAppear:(BOOL)animated
{
[_tableView addObserver:self forKeyPath:@"contentSize" options:0 context:&kvoTableContentSizeContext];
}
- (void) viewWillDisappear:(BOOL)animated
{
[_tableView removeObserver:self forKeyPath:@"contentSize"];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (context == &kvoTableContentSizeContext) {
CGFloat contentHeight = _tableView.contentSize.height;
CGFloat tableHeight = _tableView.frame.size.height;
if (contentHeight < tableHeight) {
UIEdgeInsets insets = _tableView.contentInset;
insets.top = tableHeight - contentHeight;
_tableView.contentInset = insets;
} else {
_tableView.contentInset = UIEdgeInsetsZero;
}
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}