【问题标题】:Navigation Between Two View Controller两个视图控制器之间的导航
【发布时间】: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


    【解决方案1】:

    试试这个代码。

    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
    猜你喜欢
    • 2014-10-10
    • 1970-01-01
    • 1970-01-01
    • 2014-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多