我正在使用带有初始介绍视图控制器的故事板,我希望将其转换为具有核心数据的表视图控制器。我知道初始控制器是根控制器,但由于连接到核心数据,我需要第二个控制器作为根。当我在我的app委托中执行以下操作时,出现此错误:
-[IntroViewController setViewControllers:]: unrecognized selector sent to instance 0x7465b70 2013-01-21 22:29:15.331 PManager[35522:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[IntroViewController setViewControllers:]: unrecognized selector sent to instance 0x7465b70'
我的第一个视图在故事板中被称为“introController”。
我的第二个视图是一个连接到故事板中名为“listController”的核心数据的表视图。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)options
{
// Get a reference to the navigation controller first
UINavigationController *navigationController = (UINavigationController *) self.window.rootViewController;
IntroViewController *introController = [navigationController.storyboard instantiateViewControllerWithIdentifier:@"introController"];
RootViewController *listController = [navigationController.storyboard instantiateViewControllerWithIdentifier:@"listController"];
// First item in array is bottom of stack, last item is top.
navigationController.viewControllers = [NSArray arrayWithObjects:listController, introController, nil];
// THEN get the root view controller (RootViewController)
RootViewController *rootViewController = (RootViewController *)[[navigationController viewControllers] objectAtIndex:0];
// And now pass the context
rootViewController.managedObjectContext = managedObjectContext;
[self.window makeKeyAndVisible];
return YES;
}
答案 0 :(得分:0)
改变应用的组织方式可能会更好。而不是依靠应用程序委托类来管理managedObjectContext
,而是创建另一个类,作为单例
全局管理对托管对象上下文的访问。直接从表视图控制器类和任何其他类引用该类。这样的事情:Most efficient way of passing data between views