Application tried to present modally an active controller - crashing, why?(应用程序尝试以模式方式呈现活动控制器崩溃,为什么?)
问题描述
有趣的是,我没有以情态方式呈现,但使用了Segue:
这是我触发段的方式:
_centerAndRightContainerViewController!.performSegueWithIdentifier("xxx", sender: self)
段是在界面生成器中设置的:
这里是容器类的实现,但我认为它没有任何错误,在旧的Xcode5的iOS7中,我使用了几个segues:
var _centerAndRightContainerViewController: CenterAndRightContainerViewController? = nil
var _selectedCenterAndRightContainerViewController: UIViewController? = nil
class CenterAndRightContainerViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
_centerAndRightContainerViewController = self
}
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject?) {
let fromViewController = segue.sourceViewController as UIViewController
let toViewController = segue.destinationViewController as UIViewController
if(!_selectedCenterAndRightContainerViewController) {
addChildViewController(toViewController)
view.addSubview(toViewController.view)
toViewController.didMoveToParentViewController(self)
toViewController.view.frame = self.view.bounds
} else {
let selectedCenterChildViewController = _selectedCenterAndRightContainerViewController as UIViewController
Utility.swap(selectedCenterChildViewController, toViewController: toViewController, containerViewController: self)
}
_selectedCenterAndRightContainerViewController = toViewController
}
}
这是完整的崩溃报告:
2014-08-02 12:57:30.349 PFB[66014:2653163] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <_TtC3PFB14ViewController: 0x7af35af0>.'
*** First throw call stack:
(
0 CoreFoundation 0x0104d646 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x009208bf objc_exception_throw + 44
2 UIKit 0x0155e41e presentationControllerClassForPresentationStyle + 0
3 UIKit 0x01560881 -[UIViewController presentViewController:animated:completion:] + 333
4 UIKit 0x01564e1b -[UIViewController _showViewController:withAction:sender:] + 213
5 UIKit 0x017988b1 -[UIStoryboardShowSegue perform] + 143
6 UIKit 0x01a07d43 -[UIStoryboardSegueTemplate _perform:] + 217
7 UIKit 0x015532f0 -[UIViewController performSegueWithIdentifier:sender:] + 72
8 PFB 0x0004570d _TFC3PFB23LeftTableViewController9tableViewfS0_FTGSQCSo11UITableView_23didSelectRowAtIndexPathGSQCSo11NSIndexPath__T_ + 5309
9 PFB 0x000457f5 _TToFC3PFB23LeftTableViewController9tableViewfS0_FTGSQCSo11UITableView_23didSelectRowAtIndexPathGSQCSo11NSIndexPath__T_ + 101
10 UIKit 0x0150b091 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1559
11 UIKit 0x0150b23c -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 285
12 UIKit 0x0151042d __38-[UITableView touchesEnded:withEvent:]_block_invoke + 43
13 UIKit 0x01425a9e ___afterCACommitHandler_block_invoke + 15
14 UIKit 0x01425a49 _applyBlockToCFArrayCopiedToStack + 415
15 UIKit 0x0142585e _afterCACommitHandler + 545
16 CoreFoundation 0x00f70c6e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
17 CoreFoundation 0x00f70bb0 __CFRunLoopDoObservers + 400
18 CoreFoundation 0x00f65f7a __CFRunLoopRun + 1226
19 CoreFoundation 0x00f657eb CFRunLoopRunSpecific + 443
20 CoreFoundation 0x00f6561b CFRunLoopRunInMode + 123
21 GraphicsServices 0x03fc729c GSEventRunModal + 192
22 GraphicsServices 0x03fc70d9 GSEventRun + 104
23 UIKit 0x013fc3d6 UIApplicationMain + 1526
24 PFB 0x0004f6e1 top_level_code + 97
25 PFB 0x0004f71b main + 43
26 libdyld.dylib 0x028c0ac9 start + 1
推荐答案
我自己的问题解决方案非常奇怪
1)我已经将UIStoryboardSegue子类化,添加到项目中,如下所示
import UIKit
class EmptySegue: UIStoryboardSegue {
override func perform() {
}
}
2),并将名为"_TtC3PFB10EmptySegue
"的字符串设置到情节提要中的Segue Class字段,现在可以进行转换。
不要问我是在哪里找到这根魔线的,为什么它会起作用,它是一个谜。可能只是IOS8的不良副作用。
这篇关于应用程序尝试以模式方式呈现活动控制器崩溃,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!