Search code examples
ioswindowoverlay

iPhone regain ui focus to window after overlaying another view


Am overlaying a view on the main windows like this:

    UIWindow *keyWindow = [[[UIApplication sharedApplication] delegate] window];
    [actionSheet showInView: keyWindow];

Which works fine and takes the UI Focus, the main window goes darker.

Removing the overlay like this

    [actionSheet removeFromSuperview];
    actionSheetVSTags = nil;

The action sheet goes away fine, but the main window does not have input focus (stays dark)

Have tried some of the window methods like

    UIWindow *keyWindow = [[[UIApplication sharedApplication] delegate] window];
    [keyWindow setWindowLevel: UIWindowLevelNormal];
    [keyWindow makeKeyAndVisible];

etc.

How to get the main windows to get UI focus again?

Yes, there are reasons for my madness here.


Solution

  • To dismiss the actionSheet programmatically you should use the following method:

    [actionSheet dismissWithClickedButtonIndex:buttonIndex animated:animated];
    

    This is the same method that the action sheet automatically calls when you press one of the buttons you've had setup in it. If you have setup a delegate it will call:

    – actionSheet:willDismissWithButtonIndex:
    

    before removing itself and then

    – actionSheet:didDismissWithButtonIndex:
    

    after.

    UIActionSheet Class Reference