presentViewController:animated:completion display issues in new ios 5.1 UISplitViewController

myieh picture myieh · Mar 22, 2012 · Viewed 10.8k times · Source

I've ran into some problems using UISplitViewController with presentViewController:animated:completion.

To break the problem down into its simplest form, I've created a simple project with the master/detail template. In the project I've added a + button in the navigation bar of the master view. The plus button creates a navigation controller with a simple blank view. This navigation controller is then presented using presentViewController:animated:completion. However, the presented view only displays in the master view and when you dismiss it, the master view takes up the whole screen. I can't seem to understand what is going on. Anyone else encountered this problem? Here's the code.

- (void)showViewController:(id)sender
{
LMTestViewController *masterView = [[LMTestViewController alloc] init];
[self presentViewController:masterView animated:YES completion:nil];
[masterView release];
}

Thanks for your help.

Answer

Allan Bazinet picture Allan Bazinet · Apr 20, 2012

To present modally, use the window's root view controller. Using anything else will cause things to become confused in the split view, especially when rotating, etc.

[self.view.window.rootViewController presentViewController:masterView
                                                  animated:YES
                                                completion:NULL];