質問

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.

役に立ちましたか?

解決

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.

他のヒント

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.

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.

-(void)pushView :(UIViewController *)splitViewController{
    self.rootViewControllerPre=self.window.rootViewController;
    _window.rootViewController=splitViewController;
}

-(void)popView{
    _window.rootViewController=_rootViewControllerPre;
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top