手动更新UITableView(替换NSFetchedResultsController逻辑)
我使用队列和结果控制器的组合来更新和显示一些核心数据对象。我遇到了一些异常和问题(请参阅此线程 NSOperationQueue 和 NSFetchedResultsController)。经过长时间的研究,我发现 NSFetchedResultsController 是问题所在,我决定为 uitableview 编写自己的更新逻辑。
我的新策略是: - 当我的视图加载时,我将核心数据中的所有对象提取到数组中并显示它们 - 20秒后,我尝试从网络加载新数据并更新核心数据(在第二个线程/或ns操作内部)该线程使用他自己的对象上下文...我的主上下文将忽略任何更改! - 之后我再次获取我的对象,但在临时数组中 - 现在我需要更新我的 uitableview 但我不知道如何...我必须比较两个数组并更新、删除或插入单元格..
对我来说拥有这个漂亮的插入和删除动画很重要。我的情况是所有对象都只在一个部分!但我可能对“汽车”和“酒店”有看法=> 2 个部分但不同的对象(2 个数据源数组)
有人可以为我提供一个更新 uitableview 的好例子吗?
我使用:
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath
我需要替换 NSFetchedResultsController
逻辑。
非常感谢!
i used a combination of queue and resultscontroller to update and display some coredata objects. I got some exceptions and problems (See this thread NSOperationQueue and NSFetchedResultsController). After long research i found out that NSFetchedResultsController is the problem and i decided to write my own update logic for uitableview.
My new strategie is:
- When my view loads i fetch all objects from core data into a array and display them
- After 20 Seconds i try to load new data from web and update core data (Inside of a second thread / or nsoperation) This thread uses his own objectcontext... my main context will ignore any changes!
- After that i fetch my objects again but in temporary array
- Now i need to update my uitableview but i don't know how... i have to compare both arrays and do update, delete or insert cells..
Its important for me to have this nice animations for insert and delete. I my case all objects are only in one section!! But it could be possible that i have a view with "Cars" and "Hotels" => 2 Sections but different objects (2 datasource arrays)
Can someone please provide me a good example for updating a uitableview.
I used:
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath
I need to replace NSFetchedResultsController
logic.
Thank you very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是一个太简单的答案,但我已经使用
并将其插入 - (void)viewWillAppear:(BOOL)animated 方法。
This might be too simple of an answer, but I have used
And stuck it into - (void)viewWillAppear:(BOOL)animated method.