Search code examples
iosobjective-ccocoa-touchpushviewcontrolleruistatusbar

How do I hide the status bar of a pushed view controller in objective c?


I have a signup form that pops up when a button is tapped. My aim is to hide the status bar when this modal is popped up.

Here is my code:

- (IBAction)tappedJoinButton:(id)sender {

    if (![PFUser currentUser]) {

        PFSignUpViewController *signUpViewController = [[PFSignUpViewController alloc] init];
        [signUpViewController setDelegate:self]; // Set ourselves as the delegate

        // Present the sign up view controller
        [self presentViewController:signUpViewController animated:YES completion:NULL];
    }
}

I have set View controller-based status bar appearance to yes in my plist file. Now I'd like to choose where I hide the status bar. In this situation I'd like to hide it in the signUpViewController that pops up.

I haven't seen any answers on here showing how to hide it in a pushed view controller.

How do I achieve this?

Kind regards


Solution

  • If you want to hide status bar for only one ViewController the do this:

    - (void)viewWillAppear:(BOOL)animated{
        [super viewWillAppear:animated];
        [[UIApplication sharedApplication] setStatusBarHidden:YES];
    
    }
    
    
    - (void)viewWillDisappear:(BOOL)animated{
        [[UIApplication sharedApplication] setStatusBarHidden:NO];
        [super viewWillDisappear:animated];
    }
    

    For your case it will be in PFSignUpViewController.

    Hope this helps .. :)