Ios 两视图控制器之间的导航

Ios 两视图控制器之间的导航,ios,objective-c,swift,Ios,Objective C,Swift,我有两个视图控制器。在mainViewController中,单击时有选项卡按钮,用户转到1stViewController,单击时有ui按钮,用户转到2ndViewController 在制作我的2ndViewController之前,一切正常。但是在我的程序中添加了segue函数之后,我得到了错误 无法将“Calculator.1stViewController”(0x791a8)类型的值强制转换为“Calculator.2ndViewController”(0x794c8)。 简而言之,我

我有两个视图控制器。在
mainViewController
中,单击时有
选项卡按钮
,用户转到
1stViewController
,单击时有
ui按钮
,用户转到
2ndViewController

在制作我的
2ndViewController
之前,一切正常。但是在我的程序中添加了
segue
函数之后,我得到了错误

无法将“Calculator.1stViewController”(0x791a8)类型的值强制转换为“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控制器。当我运行程序并点击按钮时,我得到了上面的错误

这是因为prepareForSegue无法确定它应该正确执行哪个按钮?如何解决它?

试试这段代码

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
        }

    }
}

我更新了我的代码,尝试用这种方式实现@axonlivelabs