Universal Master-Detail Application with Core Data and tab controller for iphone storyboard gets unrecognized selector sent to instance error

痞子三分冷 提交于 2019-12-05 20:28:13

Your problem is that you added a tab bar controller to the front of your iPhone storyboard, but in your "else" clause you say the root view controller of the window is a navigation controller -- it's not, the tab bar controller that you added is. If you put a log in as the second line in that else clause, you will see that navigationController is actually a tab bar controller, not a navigation controller. That else clause needs to look like this:

    UITabBarController *tbc = (UITabBarController *)self.window.rootViewController;
    UINavigationController *navigationController = tbc.viewControllers[3];
    MasterViewController *controller = (MasterViewController *)navigationController.topViewController;
    controller.managedObjectContext = self.managedObjectContext; 

I'm not sure about the "3" in tbc.viewControllers. I can't tell from your description which tab that navigation controller is in, so you might need to change that.

I think I got your problem.

Did you use a UITabbar object in the Xcode navigator :

Because to manage views with a TabbarController, the best way is to embed your view in a Navigation Controller, like below :

Then you got your first view embedded in a navigation controller :

You can now add a new viewController in the field and add it to the TabbarController by control-dragging from the TabbarController and select the Relationship item :

Then you got 2 views in a navigationController :

And nothing to do in the appDelegate.

Then do the last step for any other view you want embedded in the navigationController.

Hope this helps.

Martin
// Change your else part in appdelegate to this it may works.

else {

    UITabBarController *tabBarController = (UITabBarController *) self.window.rootviewController;

    // For third view in tabbar controller

    UINavigationController *navigationController = [tabBarController viewControllers] objectAtIndex: 2];

    navigationController = (UINavigationController *)self.window.rootViewController;
        MasterViewController *controller = (MasterViewController *)navigationController.topViewController;
        controller.managedObjectContext = self.managedObjectContext;

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!