I’m using a storyboard with an initial intro view controller that I want to segue to a table view controller with core data. I understand that the initial controller is the root controller but I need the 2nd controller to be the root because of connecting to core data. When I do the following in my app delegate, I get this error:
-[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'
My first view is called “introController” in the storyboard.
My second view is a table view hooked to core data called “listController” in the storyboard.
- (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;
}
It’s probably better to change the way your app is organised. Instead of relying on the app delegate class to manage the
managedObjectContext, create another class, as a singleton, tomanage access to your managed object context globally. Reference that class directly from your table view controller class and any others. Something like this: Most efficient way of passing data between views