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