The application tried to present a modally active controller - crash, why?

Interestingly, I do not represent modally, but using segue:

This is how I call segue:

_centerAndRightContainerViewController!.performSegueWithIdentifier("xxx", sender: self) 

Segue is configured in Interface Builder:

enter image description here

And here is the implementation of the container class, but I don’t think that something is wrong with it, in iOS7 in the old Xcode 5 I used several 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 complete 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 
0
source share
1 answer

My solution for my own problem is quietly strange

1) . I have subclassed the UIStoryboardSegue added to the project like this

 import UIKit class EmptySegue: UIStoryboardSegue { override func perform() { } } 

2) And set a line for the Segue class field in the Story Board called " _TtC3PFB10EmptySegue ", and the transition now works.

enter image description here

Do not ask me where I found the magic line, why it works, this is a mystery. Perhaps this is just a bad side effect of iOS8.

0
source

Source: https://habr.com/ru/post/1204295/


All Articles