我必须在其中一个视图控制器中实例化.
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];
我的应用程序崩溃了.
[self.navigationController setViewControllers:[NSArray arrayWithObject:splitViewController] animated:YES];
它适用于ios 5和ios 6.
崩溃仅发生在ios 7中.
这是错误.
[UINavigationController _setViewControllers:transition:animated:],/ SourceCache / UIKit / UIKit-2903.2 / UINavigationController.m:768
2013-10-21 18:51:37.009 TruAirSync [1723:60b] ***由于未捕获的异常’NSInternalInconsistencyException’而终止应用程序,原因是:’导航控制器中不允许使用UISplitViewControllers!’
最佳答案 只需创建另一个UIViewController并将splitviewcontroller的视图添加到它的子视图,而不是在UINavigationController中使用它.
YourContainerController *containerController = [YourContainerController new];
[containerController.view addSubview:splitViewController.view];
[self.navigationController setViewControllers:@[containerController] animated:YES];