gpt4 book ai didi

ios - 表更新时 NSFetchedResultsController 无法滚动

转载 作者:搜寻专家 更新时间:2023-10-31 23:00:47 26 4
gpt4 key购买 nike

我有一个 tableViewNSFetchedResultsController 来监听项目更新。

func controllerWillChangeContent(controller: NSFetchedResultsController) {
self.tableView.beginUpdates()
}

func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {

switch type {
case .Insert:
if let _newIndexPath = newIndexPath {
self.tableView.insertRowsAtIndexPaths([_newIndexPath], withRowAnimation: .None)
}
case .Delete:
if let _indexPath = indexPath {
self.tableView.deleteRowsAtIndexPaths([_indexPath], withRowAnimation: .None)
}
case .Update:
if let _indexPath = indexPath {
self.tableView.reloadRowsAtIndexPaths([_indexPath], withRowAnimation: .None)
}
default:
self.tableView.reloadData()
}

self.items = controller.fetchedObjects as! [Item]
}

func controllerDidChangeContent(controller: NSFetchedResultsController) {
self.tableView.endUpdates()
}

当用户添加项目时,我每 1-2 秒在数据库中更新一次,但我无法向下滚动,因为 Controller 刷新项目并将我滚动到顶部。

最佳答案

我发现了问题。这是因为我使用:

self.tableView.rowHeight = UITableViewAutomaticDimension

感谢您的回答:UITableView bouncing back to the top of a section when calling reloadRowsAtIndexPaths

关于ios - 表更新时 NSFetchedResultsController 无法滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35725884/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com