2015-07-11 68 views
1

我有两个视图控制器。在mainViewControllerTabBarButton当它点击用户转到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不能识别哪个按钮它应该执行正确?如何解决它?

回答

2

试试这段代码。

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) { 
    if (segue.identifier == "youridentifiername") { 
     //your class name 
     if let viewController: DealLandingViewController = segue.destinationViewController as? DealLandingViewController { 
      viewController.dealEntry = deal 
     } 

    } 
} 
+0

我更新我的代码试试这种方式来实现@axonlivelabs –

+0

它的工作。谢谢 – chathura