簡體   English   中英

在兩個視圖控制器之間導航

[英]Navigation Between Two View Controller

我有兩個視圖控制器。 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 Controller。 當我運行程序並單擊BarButton im時出現上述錯誤。

這是因為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
        }

    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM