Get the UIWindow which is under the UIActionSheet

Posted by Georgi on Stack Overflow See other posts from Stack Overflow or by Georgi
Published on 2013-11-08T15:02:05Z Indexed on 2013/11/08 15:54 UTC
Read the original article Hit count: 456

Filed under:
|
|

I am trying to present a new UIViewController on top of the current current UIViewController. Here is the line of code that creates the desired effect:

LoginViewController *loginViewController = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
UIViewController *rootController = [[[UIApplication sharedApplication] keyWindow] rootViewController];

[rootController presentViewController:loginViewController animated:YES completion:nil];

The problem is that I added an UIActionSheet which asks the user to confirm the desired action (which is to log out). When the user confirms the action I run the above mentioned peace of code, but the UIActionSheet is still the keyWindow. Therefore the LoginViewController is not presented on top (the rootController is null when I try to debug).

My question is: Can I somehow find the UIWindow which is under the UIActionSheet and from there get the root controller,or maybe I can dismiss programmatically the UIActionSheet when the users selects the log out action and only then execute the above code?

Thank you in advance!

© Stack Overflow or respective owner

Related posts about ios

Related posts about uiactionsheet