1
  (void)viewDidLoad {

     [super viewDidLoad];

     UINavigationController *naviController = [[UINavigationController alloc]init];

     [self.view addSubview:naviController.view];
}   

If I add navigation controller in the view, it appears about 20 pixels below status bar. I want it appears just below status bar. How do I fix this?

Vladimir
  • 170,431
  • 36
  • 387
  • 313
user698200
  • 399
  • 1
  • 7
  • 19

3 Answers3

0

Just set the frame for naviController.view

naviController.view.frame = self.view.frame;
Alex Terente
  • 12,006
  • 5
  • 51
  • 71
0

DeclareUINavigationController in the app delegate's applicationDidFinishLaunching:

UINavigationController *navController = [[UINavigationController alloc] init];

[navController pushViewController:viewControllerOfYourExample animated:YES];

logancautrell
  • 8,762
  • 3
  • 39
  • 50
sonics876
  • 947
  • 2
  • 13
  • 31
  • I think it works if I put the code in there. But I have put the code in the view. Because navigation have to appeare if I click the button. – user698200 May 03 '11 at 14:17
0

Assuming that you're adding your navigation bar at 0,0 then it looks like you're view isn't positioning correctly.

The easy fix is to move your bar to be at 0,-20

UINavigationController *naviController = [[UINavigationController alloc]init];
CGRect frame = [naviController frame];
frame.origin.y = -20;
[naviController setFrame:frame];
[self.view addSubview:naviController.view];

However, that's a hack.

Try something like this instead :

[[self view] setAutoresizesSubviews:YES];
UINavigationController *naviController = [[UINavigationController alloc]init];
[naviController setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleBottomMargin];
[self.view addSubview:naviController.view];

That might work?

deanWombourne
  • 38,189
  • 13
  • 98
  • 110
  • The First works. Second does not work. View seems to start from (0, 20). I don't understand why. Thank you. – user698200 May 03 '11 at 14:59