简体   繁体   中英

How to remove black space using Navigation Bar

I am using Navigation controller.

In my first screen their is no need of NavigationBar . As this is the Home screen.So I am hiding it using this code:

- (void)viewWillAppear:(BOOL)animated
{
   [self.navigationController setNavigationBarHidden:YES];
}

When I push to new screen I am showing the NavigationBar using this code:

 - (void)viewWillAppear:(BOOL)animated
{
   [self.navigationController NO];
}

The problem is when I come back from other screens to my HomeScreen I am getting black screen in place of navigationBar.

Here is the problem in Image:

在此处输入图片说明

White color screen is my ViewController which has navigation bar and BLue one has'n Navigation bar. How can I remove the black part.

Click on the navigation controller and go to attribute inspector and uncheck the show navigation bar option as shown in the screenshot:

在此处输入图片说明

There is a better way to do it. All you need to do is create a subclass of UINavigationController class. Set the UINavigationControllerDelegate . Add the following method in the class.

    - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if([viewController isKindOfClass: [SomeClass class]])
        [self setNavigationBarHidden: NO];
    else
        [self setNavigationBarHidden: YES];
}

OR

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

试试这个

self.navigationItem.hidesBackButton = YES;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM