【发布时间】:2014-06-10 14:11:31
【问题描述】:
我有一个使用 Core Data 和标签栏控制器的 iOS 应用程序。在第一个选项卡中,用户可以添加保存在 Core Data 中的项目。在第二个选项卡中,还有其他依赖于对 Core Data 存储的只读访问的功能。当我打开应用程序并在选项卡之间切换时,数据看起来相同,但是,如果我在第一个选项卡中添加一个项目,然后切换到第二个选项卡,它不会显示,即没有刷新。在第二个选项卡中,我最初在 viewDidLoad 中完成了提取,但我已将其移至 viewDidAppear,希望每次切换到第二个选项卡时都会进行提取(并出现相应的视图),但我仍然遇到同样的问题.
在第一个选项卡界面添加项目后,单击第二个选项卡时如何触发获取/刷新?
-(void)viewDidAppear:(BOOL)animated
{
NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error]) {
/*
Replace this implementation with code to handle the error appropriately.
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
【问题讨论】:
-
最好的猜测是您需要设置和实现 fetchcontroller 委托方法。这几乎是您直接从参考中复制的样板代码。
标签: ios objective-c