0

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!

Can Berk Güder
  • 109,922
  • 25
  • 130
  • 137
  • Does your first view have a status bar? Maybe a screenshot of the first view and the second view would be helpful – Jab Apr 25 '09 at 16:06
  • I didn't add a status bar myself. It has the same status bar that any app uses by default. –  Apr 25 '09 at 17:03

3 Answers3

5

I solved this issue by placing after:

[optionsRootController pushViewController:myOptions animated:NO];

this line:

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

Nice and easy!

August Lilleaas
  • 54,010
  • 13
  • 102
  • 111
1

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
  • 1,508
  • 11
  • 4
-1

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

Rog
  • 17,070
  • 9
  • 50
  • 73