简体   繁体   中英

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.

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.

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. Not sure why this was working for you in iOS 5 and 6. You can not push a UISplitViewController into a UINavigationController.

From Apple's documentation:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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