2

I want to push an UINavigationController object into an UISplitViewController, but I got the message below:

2014-04-30 02:25:11.215 test_demo[483:70b] Split View Controllers cannot be pushed to a Navigation Controller <UINavigationController: 0x8d34360>.

This is my push method:

- (IBAction)toggleToSplitView:(id)sender {
    SplitViewController *splitViewController = [[SplitViewController alloc] init];
    [self.navigationController pushViewController:splitViewController animated:YES];
}

In fact, I want to design a login view with a UIViewController, then, I want to push to a UISplitViewController. Anyone who can help me to solve this problem? Any help will be much appreciated.

4 Answers 4

1

man. I don't think this is a good idea to push an UIViewController to UISplitViewController. if you must to do it like this. you can use this method:

SplitViewController *splitViewController = [[SplitViewController alloc] init];
[self.view.window setRootViewController:splitViewController];

but, I think this is not a perfect solution. Especially, when you need to add some custom animation during push between different ViewController. thus, maybe you should custom a splitView and added it to an UIViewController. there are many sample code in github for custom UISplitViewController.

https://github.com/Alterplay/APSplitViewController

https://github.com/palaniraja/cUISplitViewController

I hope this help for you.

Sign up to request clarification or add additional context in comments.

2 Comments

thank you for your help. this is a good answer. my program worked.
How to close the SplitViewController when I want to quit it and return back to previous window?
1

As the message suggests, you cannot do that.

What you can do is display your SplitViewController first and then present your LoginView from your SplitViewController without animation.

3 Comments

I try to setup animation to NO, but I also got the same error.
Maybe I wasn't clear enough. When you start your app, you show the LoginView first, right ? Try showing your SplitViewController instead first. Then in the viewDidAppear of your SplitViewController , add the line that will present the LoginView : [self presentViewController:self.loginViewController animated:NO completion:nil];
I need to display the login View Controller first, and then toggle to a split view controller.
0

Actually, you're trying to push a UISplitViewController into UINavigationController object. Not vice versa. And it's not allowed. That's what error message says.

UISplitViewController is a specific controller which can be used only as a root view controller in the navigation stack. Also, it can be used only in iPad applications.

1 Comment

yes, you are right. I understand the UISplitViewController must as a root view Controller. thank you
0
-(void)pushView :(UIViewController *)splitViewController{
    self.rootViewControllerPre=self.window.rootViewController;
    _window.rootViewController=splitViewController;
}

-(void)popView{
    _window.rootViewController=_rootViewControllerPre;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.