我正在尝试使用分段控件在两个视图控制器之间切换。这是profileContainerViewController的代码,它控制开关:
class profileContainerViewController: UIViewController {
@IBOutlet weak var segmentedControl: UISegmentedControl!
let viewControllerIdentifiers = ["first", "second"]
@IBAction func valueChanged(sender: AnyObject) {
var newController = storyboard?.instantiateViewControllerWithIdentifier(viewControllerIdentifiers[sender.selectedSegmentIndex]) 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: .TransitionCrossDissolve, animations:{ () -> Void in
// nothing needed here
}, completion: { (finished) -> Void in
oldController.removeFromParentViewController()
newController.didMoveToParentViewController(self)
})
}
}
我还有一个嵌入了第一个View Controller的UIContainerView:
但是,当我加载视图时,我收到此错误:
"Could not cast value of type 'profileContainerViewController' (0x107917830) to 'userProfileViewController' (0x107917620)."
(userProfileViewController是第一个必须加载的ViewController。)