在此先感谢您的帮助!
我正在尝试使用分段控制来更改我的一个视图控制器上的容器视图内的子视图。我在 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(code = EXC_l386_INVOP, subcode=0x0)。我也在视图控制器上使用了故事板标识符。