简体   繁体   English

iOS 7中的UisplitViewController问题(崩溃)

[英]UisplitViewController issue in ios 7(crash)

I have to instantiate in one of the view controllers. 我必须实例化其中一个视图控制器。

UISplitViewController *splitViewController =  [kStoryBoard instantiateViewControllerWithIdentifier:@"splitController"];
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;
splitViewController.navigationController.navigationBarHidden = YES;

splitViewController.presentsWithGesture = NO;
UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:navigationController.topViewController action:@selector(swipeDetected:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionLeft|UISwipeGestureRecognizerDirectionRight;

[splitViewController.view addGestureRecognizer:swipeRecognizer];
CGRect frame = splitViewController.view.frame;
frame.origin.x = 0;
frame.size.height -=100;
frame.origin.y +=100;
splitViewController.view.frame = frame;
UINavigationController *masterNavigationController = [splitViewController.viewControllers objectAtIndex:0];
     MasterViewController *masterVC = (MasterViewController*)[masterNavigationController topViewController];
masterVC.currentCategory = [categoriesArray objectAtIndex:sender.tag-1];



self.navigationController.navigationBarHidden = YES;
[self.navigationController setViewControllers:[NSArray arrayWithObject:splitViewController] animated:YES];

My app crashes on this line. 我的应用程序在此行崩溃。

   [self.navigationController setViewControllers:[NSArray arrayWithObject:splitViewController] animated:YES];

It is working fine for ios 5 and ios 6. Crash occurs only in ios 7. 它对于ios 5和ios 6正常工作。仅在ios 7中发生崩溃。

This is the error. 这是错误。

[UINavigationController _setViewControllers:transition:animated:], /SourceCache/UIKit/UIKit-2903.2/UINavigationController.m:768 2013-10-21 18:51:37.009 TruAirSync[1723:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UISplitViewControllers are not allowed in a navigation controller!'

Found the answer. 找到了答案。 Hope it will help others also. 希望它也能帮助别人。

We just need to use a view controller. 我们只需要使用一个视图控制器。

UIViewController *containerVC = [[UIViewController alloc]init];

[containerVC.view setFrame:splitViewController.view.frame]; 
[containerVC.view addSubview:splitViewController.view];
[containerVC addChildViewController:splitViewController];
[splitViewController didMoveToParentViewController:containerVC];
[self.navigationController setViewControllers:[NSArray arrayWithObject:containerVC] animated:YES];

Just create another UIViewController and add you splitviewcontroller's view to it's subview than you can use it in a UINavigationController. 只需创建另一个UIViewController并将您splitviewcontroller的视图添加到它的子视图中即可,而不是可以在UINavigationController中使用它。

YourContainerController *containerController = [YourContainerController new];
[containerController.view addSubview:splitViewController.view];
[self.navigationController setViewControllers:@[containerController] animated:YES];

The UISplitViewController should be the root view of your application window. UISplitViewController应该是应用程序窗口的根视图。 Not sure why this was working for you in iOS 5 and 6. You can not push a UISplitViewController into a UINavigationController. 不知道为什么在iOS 5和6中这对您有用。您不能将UISplitViewController推入UINavigationController中。

From Apple's documentation: 根据Apple的文档:

A split view controller must always be the root of any interface you create. 拆分视图控制器必须始终是您创建的任何接口的根。 In other words, you must always install the view from a UISplitViewController object as the root view of your application's window. 换句话说,您必须始终将UISplitViewController对象中的视图安装为应用程序窗口的根视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM