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
  • 169,112
  • 36
  • 383
  • 312
user698200
  • 399
  • 1
  • 6
  • 19

3 Answers3

0

Just set the frame for naviController.view

naviController.view.frame = self.view.frame;
Alex Terente
  • 11,929
  • 5
  • 50
  • 70
0

DeclareUINavigationController in the app delegate's applicationDidFinishLaunching:

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

[navController pushViewController:viewControllerOfYourExample animated:YES];

logancautrell
  • 8,752
  • 3
  • 38
  • 50
sonics876
  • 937
  • 1
  • 13
  • 30
  • 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
  • 37,677
  • 13
  • 96
  • 103
  • 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