我與本教程中的以下核心數據:http://maybelost.com/2011/12/tutorial-storyboard-app-with-core-data/和我收到此錯誤試圖通過類之間的managedObjectContext:錯誤類別之間傳遞managedObjectContext爲
2012-04-23 09:53:13.969 PictureList[10287:fb03] -[UINavigationController setManagedObjectContext:]: unrecognized selector sent to instance 0x6d20a80
2012-04-23 09:53:13.992 PictureList[10287:fb03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setManagedObjectContext:]: unrecognized selector sent to instance 0x6d20a80'
*** First throw call stack:
(0x16ab022 0x183ccd6 0x16accbd 0x1611ed0 0x1611cb2 0x1c05 0x14386 0x15274 0x24183 0x24c38 0x18634 0x1595ef5 0x167f195 0x15e3ff2 0x15e28da 0x15e1d84 0x15e1c9b 0x14c65 0x16626 0x1afd 0x1a65)
terminate called throwing an exception(lldb)
錯誤似乎有點含糊,但我懷疑UINavigationController是造成這個問題的原因。當我運行它時,該應用程序立即崩潰。
這裏是我的Appdelegate.m這裏我想上下文傳遞給我的最初的控制器代碼:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Pass the managed object context to the root view controller (the login view)
LoginViewController *rootView = (LoginViewController *)self.window.rootViewController;
rootView.managedObjectContext = self.managedObjectContext;
....
}
return YES;
}
然後我試圖通過從我LoginViewController傳遞給下一班一個賽格。 LoginViewController.m:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
UINavigationController *navController = (UINavigationController *)[segue destinationViewController];
PictureListMainTable *piclist = (PictureListMainTable *)[[navController viewControllers] lastObject];
piclist.managedObjectContext = managedObjectContext;
}
我試圖花葯的事情是通過上下文一起到UINavigationController的:
// This code was customized to handle the navigation controller
// Pass the managed object context to the root view controller (the login view)
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
LoginViewController *rootView = (LoginViewController *)navigationController.topViewController;
rootView.managedObjectContext = self.managedObjectContext;
使用這種方法,我至少能獲取應用程序加載到登錄屏幕,但是當我嘗試繼續應用程序會崩潰。我該如何解決這個問題?
編輯:好的,發現問題。在本教程中,我並不認爲導航是在登錄登錄控制器之前嵌入的,但導航控制器實際上位於LoginViewController和PictureListMainTable之間。
你可以在下面寫下你的解答嗎?然後你可以接受它,問題就會完成(某事,某事,某事,黑暗面......):-) – 2012-05-29 12:59:43