Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Nekbeth

macrumors regular
Original poster
Feb 20, 2011
101
0
Vatican City
Hi, I have a navigation controller. I created it a template from xcode (Universal App using Core Data), the implementation is the following:

Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    // Override point for customization after application launch.

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {

        UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;

        UINavigationController *navigationController = [splitViewController.viewControllers lastObject];

        splitViewController.delegate = (id)navigationController.topViewController;



        UINavigationController *masterNavigationController = [splitViewController.viewControllers objectAtIndex:0];

        MasterViewController *controller = (MasterViewController *)masterNavigationController.topViewController;

        controller.managedObjectContext = self.managedObjectContext;

    } else {



        UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;

        MasterViewController *controller = (MasterViewController *)navigationController.topViewController;

        controller.managedObjectContext = self.managedObjectContext;

    }

    return YES;

}



Now this is all works fine, I added views and conections using Storymode with out any problems until I try to Embed In a Tab Bar Controller to my Navitagation Controller. here is crash log:

Code:
 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITabBarController topViewController]: unrecognized selector sent to instance 0x6e3c3b0'


Obviously my TabBar is not set to be the topViewController, but because the template passes important data (managed Context). I don't want to mess around and move things.




Any advice is appreciated,


Thank you
 
Obviously, you're have a UITabbarController somewhere.. And since you're trying to GET a topViewController of that object, even though you're casting.. That's why you're getting the runtime environment.
You could make a Singleton (CoreDataManager), and put it in all the managedobjects and blah in there. That would save you alot of headeaches ^_-
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.