[英]Issue with programmatically scrolling to top of UITableView or to first TableViewCell with iOS 11.2
在iOS 10.3中,可以使用以下任一代码行以编程方式滚动到UITableView的顶部:
// assumes indexPathOfFirstRow defined
self.tableView.scrollToRow(at: indexPathOfFirstRow, at: .top, animated: true)
self.tableView.scrollRectToVisible(CGRect(x: 0, y: 0, width: 1.0, height: 1.0), animated: true)
self.tableView.setContentOffset(.zero, animated: true)
在iOS 11和当前的iOS 11.2中,这些代码行会将表格视图滚动到顶部附近,但通常不会滚动到第一个单元格或顶部。
scrollToRow似乎可以正常工作,但会导致UI故障。
是否有人遇到此类问题或使用任何替代方法?
嗨,您可以尝试以下代码在我的工作端。
var cellrect = self.tableview.rectForSection(1)
self.tableview.setContentOffset(CGPoint(x: 0,y: cellrect.origin.y), animated: true)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.