我可以从 fetchedResultsController 中删除对象而不从数据库中删除该对象吗?
我一直试图从我正在使用的 tableView 中删除一个对象,而不从数据库中删除该对象,但我不知道该怎么做。
我尝试在 fetchedResultsController 上设置谓词,以过滤将 BOOL 设置为特定值的对象。然后,当我更改该值时,我希望可以将该对象保留在数据库中,但由于谓词而从 fetchedResultsController 中删除,但遗憾的是,这不起作用。
如何从 tableView 的数据源(fetchedResultsController)中删除对象,而不将其从核心数据数据库中完全删除?
请帮忙!我已经为此苦苦挣扎太久了
I have been trying to remove an object from the tableView I am working with without deleting the object from the db, and I can't figure out how to do it.
I have tried setting a predicate on the fetchedResultsController, to filter objects that have a BOOL set to a certain value. Then, when I change that value, I expect that I can get that object to stay in the db, but out of the fetchedResultsController because of the predicate, but alas, that isn't working.
How can I remove an object from my tableView's dataSource (the fetchedResultsController) without deleting it from the core data db completely?
Please help! I've been bashing my head against this for way too long
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当我需要清除获取的结果时,我总是滚动自己的表视图数据源。当您想要显示数据库中的所有内容时,
NSFetchedResultsController
对象非常有用,但当您想要动态清除一些数据时,NSFetchedResultsController 对象就不太好了。我获取数据,然后迭代结果数组以查找我想要保留的数据。好的对象被添加到一个新数组中,该数组成为我的表视图数据源的基础。当我实现此功能时,数据操作发生在模型对象中,该模型对象将数组交给实现
UITabelViewDataSource
协议方法的UITableViewController
子类。我想您可以将其实现为 NSFetchedResultsController 的子类,但我从未尝试过这种方法。I've always rolled my own table view data source when I need to weed out fetched results.
NSFetchedResultsController
objects are great when you want to show everything in your data base, but not so great when you want to weed out some of the data on the fly. I fetch the data, then iterate through the results array looking for the data I want to keep. The good objects get added to a new array, which becomes the basis of my table view data source.The times I've implemented this, the data manipulation happens in a model object which hands off the array to the
UITableViewController
subclass that implementsUITabelViewDataSource
protocol methods. I suppose you could implement this as a subclass ofNSFetchedResultsController
, but I've never tried that approach.