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?

David Guan
  • 809
  • 1
  • 8
  • 13
  • What I need to do is add a title bar to put some button on it. Is there any alternative way instead of using navigation bar? – David Guan Oct 25 '10 at 17:02

2 Answers2

3

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 :)

gabaum10
  • 3,769
  • 3
  • 48
  • 89
0

Just a quick idea,

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

Been there, done that myself ;)

Bersaelor
  • 2,517
  • 34
  • 58
  • Seems not that issue. After search, I found model vs. navigation controller seems have some issue..:-) – David Guan Oct 25 '10 at 16:24
  • 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 Oct 26 '10 at 07:13
  • 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 Oct 26 '10 at 07:16