Search code examples
iphoneuinavigationcontrolleruinavigationbaruiapplicationdelegate

compile error get navigationController from app delegate


In my AppDelegate didFinishLaunchingWithOptions, i initialized the UINavigationController

TodoTaskTableViewController *tttvc = [[TodoTaskTableViewController alloc] initInManagedObjectContext:self.managedObjectContext];
UINavigationController *navcon = [[UINavigationController alloc] init];

[navcon pushViewController:tttvc animated:NO];

[window addSubview:navcon.view];

[navcon release];

[window makeKeyAndVisible];

Then at my TodoTaskTableViewController i click on a button which push another modal view, and found that navigation bar of the modal view gets hidden below the AppDelegate's navigation bar.

So i try to hide the AppDelegate's navigation bar by setting it like:

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

[appDelegate.navigationController setNavigationBarHidden:YES animated:YES];

but i actually get a compile error : Request for member "navigationController" in something not a structure or union"

Any idea how to fix this?


Solution

  • You need to add a property called navigationController to your app delegate, and then set it to navcon.

    In AppDelegate didFinishLaunchingWithOptions:

    self.navigationController = navcon;