tags:

views:

31

answers:

2

I have a application combined with TabController and UINavigationController.

When a button is pressed, I want to pop up another window with its own UINavigationController.

-(void) buttonPushed: (UIBarButtonItem *) myButton
{

    MyNavigationController *controller = [[MyNavigationController alloc] initWithNibName:@"MyNavigationController" bundle:nil];

    MyDelegate *appDelegate = (MyAppDelegate*) [[UIApplication sharedApplication] delegate];    
    [appDelegate.rootController presentModalViewController:controller animated:YES];
}

The window shows, but I got an complete blank navigation bar and I don't see my modification of title in nib file.

I guess there is something wrong when I set the nib because when I replace the navigation controller with an basic view controller one, it loads OK.

So any idea what goest wrong?

A: 

Just a quick idea,

have you pushed a view controller onto the NavigationController before you present the NavigationController ?

Been there, done that myself ;)

Bersaelor
Seems not that issue. After search, I found model vs. navigation controller seems have some issue..:-)
David Guan
That's weird, I present a lot of navigion controllers modally. Sometimes only to be sure I have a proper UINavigationBar in the modal view.
Bersaelor
Another suggestion: You apparently subclass UINavigationController and have a new class "MyNavigationController". What is the difference to the standard NavContr.? Maybe you messed something up by subclassing it.
Bersaelor
A: 

You have to add your view to the NavController first, and then display the NavController in the modal window. Try something like this:

MyController *controller = [[MyController alloc] initWithNibName:@"controllerNib" bundle:nil];

  //Place controller in navController
UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:controller];

//Display in form sheet modal window
navController.modalPresentationStyle = UIModalPresentationFormSheet;

 MyDelegate *appDelegate = (MyAppDelegate*) [[UIApplication sharedApplication] delegate];    
[appDelegate.rootController presentModalViewController:navController animated:YES];

Once you do that, you can push a new view onto the navController anytime you want inside the controller view controller. It will automatically handle the back buttons and all that jazz. Simple as that :)

Geoff Baum