(六十六)TableView内容超过一屏时滚动到屏幕底部的方法

假设数据放置在self.chatMessage数组内,只需要让tableView滚动到最后一条数据底部即可,调用scrollToRowAtIndexPath方法:

[_tableView reloadData];
// 实现数据超过一屏时滚动到底部。
NSIndexPath *lastPath = [NSIndexPath indexPathForRow:self.chatMessage.count - 1 inSection:0];
[self.tableView scrollToRowAtIndexPath:lastPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
首先刷新数据,接着拿到最后一条数据的path,接着执行滚动。


原文地址:https://www.cnblogs.com/aiwz/p/6154152.html