0

有3个ViewController: 在此处输入图像描述

参考managedObjectContext的in ; _ 的和的参考的。_rootViewControllermanagedObjectContextAppDelegatemanagedObjectContextdisplayViewControllermanagedObjectContextmanageDataViewControllermanagedObjectContextrootViewController

DisplayViewController'view在某些控件中显示一些数据。

现在,添加新数据后,DisplayViewController'view并没有改变,除非重新启动应用程序。

为什么?

4

1 回答 1

0

If you want a view to auto-update you have two options. The easies way would be to add an observer to your managed object context like this:

[[NSNotificationCenter defaultCenter] addObserver:self
                                  selector:@selector(<#Selector name#>)
                                  name: NSManagedObjectContextObjectsDidChangeNotification
                                  object:<#A managed object context#>];

You will then get a call back any time the managed object context changes. Its up to you to filter out the relevant changes.

You can also use an NSFetchedResultsController but they are really geared towards UITableViews and not much else.

于 2013-05-24T00:30:00.010 回答