【发布时间】:2015-09-09 09:54:09
【问题描述】:
在我的UITableView 中,我使用一种方法滚动到最后一个单元格:
WLNetworkClient.sharedClient().createCommentWIthText(commentTextView.text, forItem: item) { error in
defer {
UIAlertController.showAlertFromError(error)
}
if error == nil {
self.fetchedResultsController.fetchRequest.fetchLimit += 1
try! self.fetchedResultsController.performFetch()
self.tableView.reloadData()
self.scrollTableViewToBottom()
}
}
private func scrollTableViewToBottom() {
tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: fetchedResultsController.fetchedObjects!.count - 1, inSection: 0), atScrollPosition: UITableViewScrollPosition.Bottom, animated: true)
}
但这并没有按预期工作,因为即使我在倒数第二个单元格上,表格也总是从顶部滚动。如何解决这个问题?
【问题讨论】:
-
请在该行附近显示更多代码。
-
更新了问题
-
你试过
UITableViewScrollPosition.none吗? -
感谢您的回复,但这里没有任何效果。问题不在于何时,而在于为什么从顶部开始?也许这是 Xcode 7 的问题?
-
Reload 不应该滚动到任何地方,除非它不能保持显示的原始单元格。如果你注释掉 fetch 并且滚动到底部(基本上什么都不做)它仍然滚动到顶部吗?我会剥离代码,看看你是否可以达到重新加载不影响位置的地步。
标签: ios swift uitableviewautomaticdimension