当我的应用程序进入后台时,我调用此方法:
- (void)saveArticlePosition {
self.article.position = self.position;
NSManagedObjectContext *managedObjectContext = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
NSError *error;
[managedObjectContext save:&error];
}
来自 的通知applicationDidEnterBackground
。但是,在下一次应用程序启动时,我收到此错误:
[ReadingViewController setManagedObjectContext:]: unrecognized selector sent to instance 0x844fe40
由我的这一行引起AppDelegate.m
:
controller.managedObjectContext = self.managedObjectContext;
这是这个更大部分的一部分:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
RootViewController *controller = (RootViewController *)navigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
...
到底出了什么问题?我能想到的是,当我保存到 Core Data 时,该controller
对象是类型的,但我将如何解决这个问题?RootViewController
ReadingViewController