使用 NSFetchedResultsControllerDelegate 更新 TableView 部分和NSPredicate 更改后的行
有没有办法在更改 fetchedResultsControllers NSpredicate (并执行提取)后更新 UITableView 部分和行?当我的 searchBar 中的 searchText 更改时,我想使用controllerWillChangeContent 委托方法来更新我的表。
目前在我的应用程序中,仅当核心数据发生更改时才会调用这些委托方法。更改 resultsController 谓词时不适用执行获取。
如果我只是在每次文本更改时调用 [self.tableView reloadData]
,则不会有动画,并且会有点阻碍体验。
或者我应该做一些完全不同的事情来更新每个搜索文本条目更改的 tableView 内容?
Is there a way to update a UITableView sections and rows after changing the fetchedResultsControllers NSpredicate (and executing the fetch)? I would like to use controllerWillChangeContent delegate methods to update my table when the searchText in my searchBar is changed.
Currently in my app, these delegate methods only get called when changes in coredata occur. Not when changing the resultsController predicate & executing the fetch.
If I simply call [self.tableView reloadData]
on each textchange, there are no animations and it blocks the experience a bit.
Or should I do something completely different to update the tableView contents on each search text entry change?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我再次查看了 Apple 的文档,看起来当谓词更改时不会调用 NSFetchedResultsControllerDelegate 方法:
因此,回答我自己的问题:在 NSFetchedResultsController 谓词更改后,不可能使用 NSFetchedResultsControllerDelegate 来更新表。
I've had another look into Apple's documentation and it looks like the NSFetchedResultsControllerDelegate methods are not called when a predicate has changed:
So, to answer my own question: It's not possible to use NSFetchedResultsControllerDelegate to update the table after NSFetchedResultsController predicate changes.
尝试调用
[self.tableView reloadData]
Try to call
[self.tableView reloadData]
in您可以尝试使用
UITableView
方法reloadSections:withRowAnimation:
传入包含所有部分的NSIndexSet
。这样您应该重新加载整个内容,但仍然可以获得您选择的动画。如果要添加和删除行,则需要使用
insertSections:withRowAnimation:
和removeSections:withRowAnimation:
。如果您要同时进行多项更改,则还应该在调用beginUpdates
和endUpdates
之间进行这些更改。You could try using the
UITableView
methodreloadSections:withRowAnimation:
passing in anNSIndexSet
with all of your sections. That way you should have the whole thing reload but still get the animation of your choice.If you are adding and removing rows you will need to use
insertSections:withRowAnimation:
andremoveSections:withRowAnimation:
. If you're doing a number of changes at once you should also do them between calls tobeginUpdates
andendUpdates
.来自 NSFetchedResultsController 类参考:
由于您已经更改了谓词,因此必须再次调用performFetch:,然后委托将处理从那里更新表的操作。
From NSFetchedResultsController Class Reference:
Since you have changed the predicate, you must call performFetch: once again and then the delegate will handle updating the table from there.