1
我有两个视图控制器。在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控制器。当我运行该程序,然后单击BarButton即时获取上述错误。
它是因为prepareForSegue不能识别哪个按钮它应该执行正确?如何解决它?
我更新我的代码试试这种方式来实现@axonlivelabs –
它的工作。谢谢 – chathura