【发布时间】:2015-07-11 13:11:41
【问题描述】:
我有两个视图控制器。在mainViewController 中有TabBarButton 当它点击用户转到1stViewController 并且有UIButton 当它点击用户转到2ndViewController。
在让我的2ndViewController 之前一切正常。但在我的程序中添加segue 函数后,我得到了错误。
could not cast value of type 'Calculator.1stViewController' (0x791a8) to 'Calculator.2ndViewController' (0x794c8).
简单来说我的代码是
@IBAction func CalculateGpa(){
//Calucation Goes Here
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var AnotherName : 2ndViewController = segue.destinationViewController as! 2ndViewController
//Code here
}
UIButton 执行 segue,BarButton 什么也不做,它只是转到 1stView Controller。当我运行程序并单击 BarButton 时,我得到了上述错误。
它是因为 prepareForSegue 无法识别它应该执行到哪个按钮?如何解决?
【问题讨论】:
标签: ios objective-c swift