【发布时间】:2012-01-19 11:43:07
【问题描述】:
我遇到了一个问题,希望这里有人能提供帮助。
我正在编写一个包含 ViewController 容器的应用程序。当用户操作 SegmentedController 时,主控制器交换各种子控制器。
它似乎工作正常,但我发现了一个漏洞。如果我选择段太快,我可以让应用程序崩溃并出现以下错误:
2012-01-19 04:29:39.539 MyApp[1057:fb03] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“儿童视图控制器 (ChildViewController1): 0x6e91480 和 ChildViewController1: 0x6e8dca0 调用时必须有共同的父视图控制器 -[UIViewController transitionFromViewController:toViewController:duration:options:animations:completion:]'
问题似乎是我在动画运行时触发了一个动作(并且子控制器正在被换入和换出),这就是问题所在,但我不确定如何保护UI 在动画运行时执行此操作。任何想法将不胜感激。这是运行 VC 交换的代码:
- (IBAction)selectPage:(id)sender {
NSLog(@"Page Selected");
UIViewController *newViewController = [[self patientChartViewControllers] objectAtIndex:[sender selectedSegmentIndex]];
[self addChildViewController:newViewController];
[[self navigationItem] setTitle:[newViewController title]];
[self transitionFromViewController:[self currentPatientChartViewController] toViewController:newViewController duration:0.50 options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[[[self currentPatientChartViewController] view] removeFromSuperview];
newViewController.view.frame = self.view.bounds;
[[self view] addSubview:[newViewController view]];
}
completion:^(BOOL finished){
[newViewController didMoveToParentViewController:self];
[[self currentPatientChartViewController] removeFromParentViewController];
[self setCurrentPatientChartViewController:newViewController];
}];
}
【问题讨论】:
-
您找到解决方案了吗?我遇到了完全相同的问题(iOS 7.1.1)并且在动画运行时禁用分段控件也对我没有帮助。