Question

I thought it was easy as [myWindow resignKeyWindow] and [self.window makeKeyAndVisible] but I guess not… Would you guys know what to do?

Thanks :)

Was it helpful?

Solution

Do not invoke -resignKeyWindow directly, it was meant to be overridden to execute some code when your UIWindows gets removed. In order to remove old window you need to create new instance of UIWindow and make it -makeKeyAndVisible, the old window will resign its key status. In iOS 4 it will even garbage collect your old UIWindow, provided you don't have any references to it. Doing this in iOS 3.x would have disastrous effects. Warned ya.

OTHER TIPS

The correct way to hide a window is to set the hidden property to YES. To remove it from UIApplication's windows property you just release the window (in ARC you set all references to nil).

Of course you would want to have another window in place at this time.

If you have any window other than app window, use it ..

let mainWindow = UIApplication.shared.delegate?.window
mainWindow??.makeKeyAndVisible()

You cannot remove the window from the app delegate. However you can remove any custom windows created.

To remove the window you must first provide a replacement. So we get the default window.

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

We now have access to the default window via the app delegate's window property.

Now get the original or custom navigation controller. Assign self to rootViewController.

Calling makeKeyandVisible removes any windows and assigns the app delegate's window as the key window. Set rootViewController to the navigation controller you just created and you are good to go!

DEMONavigationController *demoNav = [[DEMONavigationController alloc]initWithRootViewController:self];
[appDelegate.window makeKeyAndVisible];
appDelegate.window.rootViewController = demoNav;

I have the same issue, it may helps.

You needs to destroy all strong ref before remove and dealloc a windows, especially the rootWindowController. I think below code is enough to delete any window:

[self.window.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
self.window.rootViewController = nil;
[self.window resignKeyWindow];
[self.window removeFromSuperview];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top