-2

I have a view controller where

- (BOOL)prefersStatusBarHidden {
     return YES;
}

is getting called before

- (void)viewDidLoad
{
   [super viewDidLoad];
}

I am another view controller where the viewDidLoad is getting called first and then the prefersStatusBarHidden.

I want prefersStatusBarHidden to be called before viewDidLoad.

Please help!

Jatin Patel - JP
  • 3,725
  • 2
  • 21
  • 43
Dave
  • 494
  • 6
  • 21
  • 1
    i do not think that you have any influence on the order of calling. what do you need that order for? – André Slotta May 08 '15 at 10:39
  • You can't guarantee which is called first. – Schemetrical May 08 '15 at 10:40
  • I need this. I am setting up some views before setting up views I want status bar to be hidden. It is an animation app. With the status bar the initialisation is getting some design distortion. – Dave May 08 '15 at 10:41
  • you know that your statusbar will be hidden when the viewcontroller comes on screen. isn't that enough to setup your animations with that in mind? – André Slotta May 08 '15 at 10:43
  • Actually it does not do like this. First views are coming and then status bar is getting hidden. – Dave May 08 '15 at 10:55
  • Really unfortunate to get down voted. Not only me, some others also faced the problem. – Dave May 08 '15 at 12:39

2 Answers2

2

for a simple view controller in a tab bar controller I got this order for iOS 8.3

13:57:46.610 loadView
13:57:46.612 viewDidLoad
13:57:46.612 updateViewConstraints
13:57:46.613 viewWillLayoutSubviews
13:57:46.613 viewDidLayoutSubviews
13:57:46.614 viewWillAppear:
13:57:46.616 prefersStatusBarHidden
13:57:46.616 viewWillLayoutSubviews
13:57:46.616 viewDidLayoutSubviews
13:57:46.712 viewDidAppear:

The reason you see the viewWillLayoutSubviews/viewDidLayoutSubviews calls twice, that any transitioning animation is happening in between.

I would expect that if there is a animation, also the disappearing of a statusbar would be animated and that might be the reason the call for prefersStatusBarHidden happens there.

So whatever you want to do in viewDidLoad is better suited in viewWillLayoutSubviews or viewDidLayoutSubviews

I used this code: https://github.com/vikingosegundo/ofaexample/blob/298c56346f49c467c9f54e9cf18cd5ec604c1fdc/OFAExample/SecondViewController.m

vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
1

This seems to be the order the methods are called:

  1. initWithCoder:
  2. awakeFromNib
  3. willMoveToParentViewController:
  4. prefersStatusBarHidden
  5. preferredStatusBarUpdateAnimation
  6. loadView
  7. prepareForSegue:sender:
  8. viewDidLoad
  9. extendedLayoutIncludesOpaqueBars
  10. edgesForExtendedLayout
  11. viewWillAppear:

...

Source: https://bradbambara.wordpress.com/2014/07/31/object-life-cycle-uiviewcontroller/

So you need to rethink your architecture so you're not assuming viewDidLoad is called before prefersStatusBarHidden

Sunkas
  • 9,542
  • 6
  • 62
  • 102
  • With break points strangely viewDidLoad is called before prefersStatusBarHidden thats what I am combating. – Dave May 08 '15 at 11:07
  • Are you sure it's the same viewController? Can you check the stacktrace that they are not called manually from somewhere else? – Sunkas May 08 '15 at 11:22
  • Yes it is same view controller. – Dave May 08 '15 at 12:40
  • And you have verified that they are not called manually? Anything other that is different with the view controller or how it's displayed? – Sunkas May 08 '15 at 13:25