面对不同的需求使用不同的方(zi)式(shi)
1.在获取不到tableView准确的属性和数据源的时候
//在viewWillAppear:方法中调用有效(tableView没有确定contentOffset之前调用才会生效)
[_tableView setContentOffset:CGPointMake(0, CGFLOAT_MAX)];
2.在可以获取到tableView准确属性,但不清楚数据源的情况下(数据源可有可无)
//在viewDidAppear:方法中调用有效(tableView已经显示之后才会生效)
if (_tableView.contentSize.height > _tableView.frame.size.height) {
self.view.userInteractionEnabled = NO;
CGPoint offset = CGPointMake(0, _tableView.contentSize.height - _tableView.frame.size.height);
[_tableView setContentOffset:offset animated:YES];
}
3.在可以获取到tableView准确属性和数据源的情况下
//在可以获得tableView正确属性的任何地方都可以调用此方法将tableView滚动到底部
[_tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:lastRow inSection:lastSection] atScrollPosition:UITableViewScrollPositionBottom animated:YES];