iPhone: Weird space at the top of UINavigationController

前端 未结 6 662
轻奢々
轻奢々 2020-12-08 16:45

I\'m having a strange problem with adding a UINavigationController to my iPhone application. I add the controller as follows:

myViewController *viewControlle         


        
6条回答
  •  囚心锁ツ
    2020-12-08 17:33

    What does the line

    UIView *finalView = myeNavigationViewController.view;
    

    add to the code? It's redundant as you can add the view directly without assigning it to a UIView first - plus it's incorrect as it references the myNavigationController and not navigationController..
    I tend to do this

    myViewController *viewController = [[myViewController alloc] initWithNibName:@"myView" bundle:nil];    
    myNavigationViewController *navigationController = [[myNavigationViewController alloc] initWithRootViewController:viewController];
    [navigationController.view setFrame: [self.view bounds]];
    navigationController.delegate = self;
    [self.view addSubview:[navigationController view]];
    

    Setting the frame to the bounds also removes the white space at the top you were asking about.

提交回复
热议问题