我正在尝试使用contentOffset method.This方法滚动表格到最后一行,当数据不多时工作良好,但如果用户滚动到很多,它确实需要表格到最后一个单元格。我正在使用下面的代码
self.delegate.table.setContentOffset(CGPointMake(0, table.contentSize.height - table.frame.size.height), animated: false)
发布于 2017-02-22 09:16:49
我想最好的方式是打电话给
func scrollToRow(at indexPath: IndexPath,
at scrollPosition: UITableViewScrollPosition,
animated: Bool)
在UITableView
上,请参阅here
发布于 2017-02-22 09:19:45
为什么不使用scrollToRow
方法。
let lastIndex:NSIndexPath = NSIndexPath(forRow: tableView.numberOfRowsInSection(0) - 1, inSection: 0)
tableView.scrollToRowAtIndexPath(lastIndex, atScrollPosition: .Middle, animated: true)
滚动所需的时间取决于contentSize。奇怪的是,当animated设置为false时,仍使用此时间。要使它更快,请在动画块中设置您自己的持续时间。
UIView.animateWithDuration(aSmallValue) {
self.tableView.scrollToRowAtIndexPath(lastIndex, atScrollPosition: .Middle, animated: true)
}
发布于 2017-02-22 11:03:03
试试这个,它对我很有效,objective-c的代码
NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:([self.tableView numberOfRowsInSection:0] - 1) inSection:0];
[[self tableView] scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];
Swift 3.0的代码
let scrollIndexPath:IndexPath = IndexPath(row: (tblView.numberOfRows(inSection: 0)-1), section: 0)
tblView.scrollToRow(at: scrollIndexPath, at: .bottom, animated: false)
https://stackoverflow.com/questions/42387157
复制相似问题