Search code examples
iosobjective-cuiviewcontrolleruistoryboarduistoryboardsegue

UIStoryboard Reference and root view controller


I have a "Main" storyboard, inside this storyboard i have a Storyboard reference entity that links to another storyboard "Login". I'm noticing that when i attempt to access the view currently onscreen with the following:

[[[[UIApplication sharedApplication]delegate]window]rootViewController]

It's returning me the view on the "Main" Storyboard, but if i attempt to push a UIAlertController on this view i get the following error:

Warning: Attempt to present <UIAlertController: 0x1839a000> on <ViewController: 0x17633ad0> whose view is not in the window hierarchy!

Is there a reason i can't push this view on top, if not how do i get the actual uiviewcontroller currently being displayed from the "Login" storyboard?


Solution

  • If you are presenting UIAlertController from your viewDidload then it may happen like this because when view is loading at that time it is not in windows hierarchy until it load completely.

    Second thing you must present UIAlertController on top most view controller like,

     [self presentViewController......];
    

    not on windows rootViewController. So, it's depends hows you are doing this.