views:

731

answers:

3

I've got a button on a view. When I click on it, it should load another view, one with a novigation controller. So far I've got this, the button calls this method:

-(IBAction)loadOptionsView:(id)sender {

     if (self.optionsRootController == nil) {

          //optionsRootController is declared as: UINavigationController *optionsRootController;
          optionsRootController = [[UINavigationController alloc] init];

          //Options is a UIViewController
          Options *myOptions = [[Options alloc] initWithNibName:@"OptionsMenu" bundle:nil];
          [optionsRootController pushViewController:myOptions animated:NO];
          [myOptions release];
     }

     [self.view addSubview:optionsRootController.view];

}

What happens when I click the button is that it loads the xib file OptionsMenu on top of the current screen, but there's a gap at the top of the size of the status bar, so I can see the view below. Any help? What's the right method to load a new view that contains a navigation controller?

Thank you all!

+1  A: 

I think UINavigationController's designated initializer is

  - (id) initWithRootController:(UIViewController *)rootController

So your code above would be better expressed as

  //optionsRootController is declared as: UINavigationController *optionsRootController;

  //Options is a UIViewController
  Options *myOptions = [[Options alloc] initWithNibName:@"OptionsMenu" bundle:nil];
  optionsRootController = [[UINavigationController alloc] initWithRootController: myOptions];
  [myOptions release];
Christian Brunschen
It produces the same result :(
A: 

Is the VIew in your nib the right size for the whole screen? Try turning off the simulated status bar in IB.

Roger Nolan
+1  A: 

I solved this issue by placing after: [optionsRootController pushViewController:myOptions animated:NO];

this line: [optionsRootController.view setFrame: [self.view bounds]];

Nice and easy!