ios - 魔法记录 - 丢失我的实体信息

标签 ios objective-c core-data magicalrecord

我有一个应用程序,它有一个包含客户信息的 TableView。

如果点击一个单元格,我会加载该客户的详细信息。

我正在使用 Magical Record 来管理我的所有实体。

我在做什么:

1) Load all the CUSTOMER entity on the viewDidLoad of my TableView.
2) User click to see the detail of the customer
3) Pass to the ViewController of the detail the object that represent the entity CUSTOMER (only one).

一切正常。

问题是,如果用户选择重新加载 TableView,我会这样做:

1) Go to the API to get all the customers
2) [Customer truncateAll]
3) Create all the entities back on CoreData
5) [[NSManagedObjectContext defaultContext] saveToPersistentStoreAndWait]
6) Reload tableview

但是,如果用户在此过程中点击查看客户的详细信息,下面的 ViewController 将暂时正确显示客户信息。然后 [Customer truncateAll] 发生的所有信息都死掉了。

如何防止这种情况发生?

非常感谢!

最佳答案

您可以使用 NSFetchedResultController 来监听您的 Customer 实体更改。当您的 API 调用完成并且您在应用程序的其他地方创建了适当的实体时,您将在 Controller 中收到有关这些更改的通知,然后您可以重新加载数据。如果您不熟悉这个概念,请查看 here .

关于ios - 魔法记录 - 丢失我的实体信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23116261/

相关文章:

ios - 强制用户在 iOS 中以编程方式更新应用程序

ios - 我正在通过应用程序绑定(bind)工作计时器

ios - react native 性能监视器

ios - 在 Xcode6.2 中的 iOS 7 设备上运行带有 WatchKit 扩展的 iOS 应用程序

objective-c - 如何通过Health Kit将健康记录添加到健康App

ios - Swift - 删除 CoreData 行

ios - 在Apple Review之前获取App Store URL

ios - 如何让 UIView 在滚动时改变它的大小

iphone - CoreData Context 合并后如何获取对象

iphone - CoreData内存管理问题