如何在 NSFetchedResultsController 中触发重新加载而不更改获取的对象?
在我的 iPhone 应用程序中,我有一个 NSFetchedResultsController 在 UITableView 中显示用户对象。用户对象有0-多个日志对象。日志对象的摘要与其用户对象一起显示在 UITableView 中。
我的应用程序使用选项卡栏,因此日志记录选项卡中的用户输入要求触发用户选项卡的 NSFetchedResultsController 重新加载。
到目前为止,我通过写入 User 对象来做到这一点:
log.user = nil;
log.user = [User current]; // Same as before. Just triggering a reload.
NSError *error = nil;
[myManagedObjectContext save:&error];
这工作正常,但看起来有点像黑客。
有更好的方法吗?就像指定 Log 对象中的更改也应该传播到 User 对象一样?
In my iPhone app, I have an NSFetchedResultsController showing User objects in a UITableView. The User Objects have 0-many Log objects. A summary of the Log objects are shown together with their User object in the UITableView.
My app uses a tab bar, so user input in the logging tab require that the user tab's NSFetchedResultsController is triggered to reload.
So far I do it by writing to the User object:
log.user = nil;
log.user = [User current]; // Same as before. Just triggering a reload.
NSError *error = nil;
[myManagedObjectContext save:&error];
This works fine, but seems a bit like a hack.
Is there a better way to do this? Like specifying that changes in the Log object should propagate to the User object too?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
但你为什么要这样做呢?仅当有新数据可供获取时才应重新加载。如果有新数据,则保存
NSManagedObjectContext
是正确的操作。您的根本目标是什么?
But why would you want to do this? It should only reload when there is new data for it to fetch. If there is new data then a save of the
NSManagedObjectContext
is the right action.What is your underlying goal?