Jack Nutkins
Jack Nutkins

Reputation: 1555

Removing grey bar above UINavigationController in a UITableView

I am creating a UITableView with a UINavigationController programmatically:

- (void) displayView:(int)intNewView{

    NSLog(@"%i", intNewView);
    [currentView.view removeFromSuperview];
    [currentView release];

    switch (intNewView) {
        ......

        case 5:
            vc = [[RootViewController alloc] init];
            currentView = [[UINavigationController alloc] initWithRootViewController:vc];
            [currentView setTitle:@"Events"];
            break;
    }

    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationDuration:0.5];

    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
                           forView:self.view 
                             cache:YES];

    [self.view addSubview:currentView.view];

    [UIView commitAnimations];
}

However when the view appears there is an annoying grey bar perched above the navigation controller, none of my other views suffer from this. Just the view with the UITableView and NavigationController.

Any ideas whats causing this and how to remove it?

Thanks,

Jack

Upvotes: 0

Views: 1592

Answers (2)

Jack Nutkins
Jack Nutkins

Reputation: 1555

When the UINavigationController is initialised, it does so expecting the iPhones status bar to be present at the top of the screen. Therefore, the view is essentially moved down a little in order to accommodate this. BUT, as my UINavigationController is inside my RootViewController, the UINavigationController does not have to accommodate for the status bar and so can be "moved up" the appropriate distance using the following line placed inside the viewDidLoad method of my RootViewController:

self.navigationController.view.frame = CGRectMake(0, -20, 320, 480);

Now when the program runs, there is no grey bar/ grey space at the top of my view.

Thanks for all your help, pointed me in the right direction.

Jack

Upvotes: 1

Mr. Berna
Mr. Berna

Reputation: 10645

A UINavigationController expects to be the root view in the window, therefore it includes the status bar. If it is put inside another view that includes a status bar, a second empty status bar is drawn, which looks like "an annoying grey bar perched above the navigation controller."

Upvotes: 2

Related Questions