Get the UIWindow which is under the UIActionSheet
- by Georgi
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!