应用程序尝试以模态方式呈现一个活动控制器 - 崩溃,为什么?

时间:2014-08-02 10:27:05

标签: ios segue

有趣的是我不会以模态方式呈现,但使用segue:

这是我如何触发segue:

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

Segue在Interface Builder中设置:

enter image description here

这是容器类的实现,但我不认为它有任何问题,在iOS7的旧Xcode 5中我使用了几个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 个答案:

答案 0 :(得分:0)

我对自己问题的解决方法很安静

1)我已经将UIStoryboardSegue子类化,添加到项目中,就像这样

import UIKit

class EmptySegue: UIStoryboardSegue {


    override func perform() {

    }
}

2)并在故事板中的Segue Class字段中设置一个名为:&#34; _TtC3PFB10EmptySegue&#34;的字符串,转换现在正在运行。

enter image description here

不要问我在哪里找到了魔法弦,为什么它在起作用,这是一种谜。也许只是iOS8的一个不好的副作用。