aryaxt
aryaxt

Reputation: 77596

Display Modal on top of a UISplitViewController?

This question has been asked before, but non of the answers I found were correct, or atleast they don't work on iOS 5

I'm trying to display a modal (on iOS 5) on top of my UISplitViewController, and so far I had non lucks. Most post mention to present the modal from my mainViewController, and that doesn't seem to work for me.

I tried presenting the modal using segue, or doing it manually in code, from both UISplitViewController, and my master UIViewController and It always gives me the following error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a Split View Controllers modally

This error is wrong, I didn't try to display the splitView modally, I tried to display a modal from a splitView

Any other solutions?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   NSLog(@"%@", self.window.rootViewController);
   // It prints out UISplitViewController


    // I tried this
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UIViewController *viewController = [storyBoard instantiateViewControllerWithIdentifier:@"LoginViewController"];
    [self.window.rootViewController presentModalViewController:viewController animated:NO];

    // Also tried this
    [self.window.rootViewController performSegueWithIdentifier:@"LoginSegue"];

    return YES;
}

Upvotes: 0

Views: 1115

Answers (1)

pre
pre

Reputation: 3506

The error messages advises that your loginViewController is a UISplitViewController. That wont work, as you can't show a split view modally.

Otherwise I can see no error in your code, and I did what you want to achieve on iOS 5.1 without any problem, using presentModalViewController:animated:.

Upvotes: 1

Related Questions