5

so i'm using the "Utility Application" template in Xcode and have the Main View Controller, where the user can hide and show the status bar using a button. I've also got the Flipside View Controller, using a modal segue, which has a done button to return to the Main VC. I've set it up so that whenever viewing the Flipside VC, the status bar is always NOT hidden. This means that if the user hides the status bar on the Main VC and transitions to the Flipside VC, it will animate on and if the user didn't hide the status bar and they transition, nothing happens to the status bar.

That's all good, the problem is transitioning back from the Flipside VC to Main VC. I need a condition to check the hidden state of the status bar in the Main VC, which would be called in the Flipside VC when pressing the done button.

I've looked into using a BOOL as well as NSNotificationCenter to send a message to the Flipside VC about the state of the status bar.

I had this code:

-(BOOL)checkStatusBarHidden:(id)input
{
    BOOL result;

    if ([UIApplication sharedApplication].statusBarHidden = YES)
    {
        result = YES;
    }
    else
    {
        result = NO;
    }

    return result;
}

But this is all just guessing and thinking I might be able to use it somewhere to inform the Flipside VC of the status bar state. I thought of maybe changing the

[UIApplication sharedApplication].statusBarHidden = YES)

to something like

self.statusBarHidden = YES //which of course isn't going to work

But anyway, as I said it's guessing and i'm not sure what to do.

Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235
Ben
  • 65
  • 2
  • 6
  • for the God sake why do you need an `if` statement there?. Couldn't you just write `return [UIApplication sharedApplication].statusBarHidden`? **EDIT** It's even wrong since your are assigning instead of comparing, due to the use of `=` instead of `==`. – Gabriele Petronella Jan 27 '13 at 20:06
  • @GabrielePetronella Yup, I dunno I suppose I could, sorry but i'm not very experienced with programming that's why i'm asking here, but that was just some extra info, not really part of the question :/ – Ben Jan 27 '13 at 20:12
  • @GabrielePetronella Yea, i'm assigning :( sorry, wasn't asking about how correct the syntax was though – Ben Jan 27 '13 at 20:20
  • http://stackoverflow.com/questions/19774968/under-ios-7-how-do-i-hide-and-show-status-bar-on-the-fly-whenever-i-want-to/19867698#19867698 – John Riselvato Feb 20 '14 at 16:59

1 Answers1

2

You may think of storing the information about the status bar state in the MainViewController using a property, e.g.

In your MainViewController.h

@property (nonatomic, assign) BOOL statusBarHidden;

then you can access that value from the FlipsideViewController using the presentingViewController property.

In your FlipsideViewController.h

MainViewController * mainVC = self.presentingViewController;
if (mainVC.statusBarHidden) {
   // Do stuff
}

As a final remark, please change your checkStatusBarHidden: method to something like

- (BOOL)checkStatusBarHidden {
    return [UIApplication sharedApplication].statusBarHidden;
}
Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235
  • OK that seems good thanks a lot. One thing though, if I put: MainViewController * mainVC = self.presentingViewController; if (mainVC.statusBarHidden) { // Do stuff } in the FlipsideViewcontroller, I get the error **Unknown type name...MainViewcontroller** I'm guessing because I didn't import the **Main VC.h file**, but I can't or don't even need that do I? – Ben Jan 27 '13 at 20:37
  • Yes of course you need to add `#import "MainViewController.h` into your `FlipsideViewController` – Gabriele Petronella Jan 27 '13 at 20:48