简体   繁体   English

模态视图控制器崩溃

[英]Modal View Controller crash

I have three views inside a scroll view. 我在滚动视图中有三个视图。 I've added them via the following code; 我通过以下代码添加了它们;

[self.scrollView addSubview:[aViewController view]];

When I scroll the view I want to present a modal view controller with its own navigation controller, however this causes a crash. 当我滚动视图时,我想提供一个模态视图控制器及其自己的导航控制器,但是这会导致崩溃。 Here's the code I'm using to show the modal view 这是我用来显示模式视图的代码

    MyVC *vc = [[MyVC alloc] initWithNibName:@"VC" bundle:nil];
self.navController.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
self.navController.viewControllers = [NSArray arrayWithObject:vc];
[vc release];
[self presentModalViewController:self.navController animated:YES];

And the crash I get is: erminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempting to begin a modal transition from to while a transition is already in progress. 我崩溃的原因是: 由于未捕获的异常“ NSInternalInconsistencyException”而终止应用程序,原因:“尝试在已进行过渡的情况下从开始进行模式过渡。 Wait for viewDidAppear/viewDidDisappear to know the current transition has completed' 等待viewDidAppear / viewDidDisappear知道当前转换已完成'

Any help would be greatly appreciated. 任何帮助将不胜感激。

You cann't present current navigation controller. 您无法显示当前的导航控制器。 Present instead your MyVC viewcontroller MyVC您的MyVC ViewController

MyVC *vc = [[MyVC alloc] initWithNibName:@"VC" bundle:nil];
vc.modalPresentationStyle = UIModalPresentationFormSheet;
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self
presentModalViewController:vc animated:YES]; 
[vc release];

You can also create a new hierarchy of view controllers, push them to a new navigation controller and present it. 您还可以创建视图控制器的新层次结构,将它们推到新的导航控制器中并进行显示。

You should not be trying to present a view controller's navigation controller from within itself. 您不应该试图从自身内部呈现视图控制器的导航控制器。 Instead, create a new navigation controller for your modal view controller: 而是为模态视图控制器创建一个新的导航控制器:

MyVC *vc = [[MyVC alloc] initWithNibName:@"VC" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

[self presentModalViewController:navigationController animated:YES];
[vc release];

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

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