问题
Interesting that I don't present modally, but using segue:
This how I trigger segue:
_centerAndRightContainerViewController!.performSegueWithIdentifier("xxx", sender: self)
Segue is set up in Interface Builder:
And here is the container class implementation, but I don't think any wrong is with it, in iOS7 in old Xcode 5 I used several of 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
}
}
And here is the full crash report:
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:
My solution for my own problem is quiet strange
1) I have subclassed UIStoryboardSegue, added to project, like this
import UIKit
class EmptySegue: UIStoryboardSegue {
override func perform() {
}
}
2) And set to the Segue Class field in Story Board a string called: "_TtC3PFB10EmptySegue", and transition is working now.
Don't ask me where I found the magic string, why it is working, it is a mistery. Maybe just a bad side effect of iOS8.
来源:https://stackoverflow.com/questions/25094028/application-tried-to-present-modally-an-active-controller-crashing-why