使用分段控件进行容器视图时的错误代码

时间:2015-07-09 18:49:16

标签: ios swift uisegmentedcontrol exc-bad-instruction

提前感谢您的帮助!

我正在尝试使用分段控件来更改我的一个视图控制器上的容器视图中的子视图。我在SO上找到了一个很好的答案,下面是以下代码:

@IBAction func segmentedControlChange(sender: AnyObject) {

    var newController = storyboard?.instantiateViewControllerWithIdentifier(viewControllerIdentfiers[sender.selectedIndex]) as! UIViewController
    let oldController = childViewControllers.last as! UIViewController

    oldController.willMoveToParentViewController(nil)
    addChildViewController(newController)
    newController.view.frame = oldController.view.frame

    transitionFromViewController(oldController, toViewController: newController, duration: 0.25, options: UIViewAnimationOptions.TransitionFlipFromRight, animations: {
        () -> Void in
        //nothing needed here
        }, completion: { (finished) -> Void in
            oldController.removeFromParentViewController()
            newController.didMoveToParentViewController(self)

    })
}

当我在模拟器中运行然后单击分段控件时,我想出了THREAD 1:EXC_BAD_INSTRUCTION(代码= EXC_l386_INVOP,子代码= 0x0)。我也在视图控制器上使用了故事板标识符。

1 个答案:

答案 0 :(得分:0)

尝试获取故事板

let storyboard = UIStoryboard(name: "Main", bundle: nil)