5
votes

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.

1
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
@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
@GabrielePetronella Yea, i'm assigning :( sorry, wasn't asking about how correct the syntax was thoughBen

1 Answers

2
votes

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;
}