2016-09-22 241 views
0

我從一個ViewController有兩個segues。點擊LogOut按鈕時Segges衝突

一是應該在註銷按鈕,當點擊運行(現在崩潰)(進入登錄視圖控制器),另一個運行(工作好)上的視頻縮略圖,當點擊。

因爲我需要從服務器獲取視頻和我前往(WatchVideoViewController)的視圖控制器顯示它,我做下面的代碼:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 

     // Get a reference to a destination View Controller 
     let detailViewController = segue.destinationViewController as! WatchVideoViewController 

     // Set the selected video property of the destination view controller 
     detailViewController.selectedVideo = self.selectedVideo 
    } 

正如你可能已經猜到這個代碼運行時執行每個賽門鐵克,這就是爲什麼我的LogOut賽格崩潰。

Could not cast value of type 'AppName.LoginViewController' to 'Appname.WatchVideoViewController'. 

下面是代碼,我叫塞格斯件:

@IBAction func pressLogOutButton(sender: AnyObject) { 
     self.performSegueWithIdentifier("logOutSegue", sender: self) 
    } 


// Handle event when user selects a cell(thumbnail) 

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 

     // Take note of which video is selected 
     self.selectedVideo = self.videos[indexPath.row] 

     // Call the segue 
     self.performSegueWithIdentifier("goToVideo", sender: self) 
    } 

有什麼辦法來避免運行prepareForSegue調用pressLogOutButton什麼時候?非常感謝!

+0

您可以檢查是否標識的prepareForSegue – Misha

+0

@Misha的值可以請你告訴它的外觀在代碼中。 我不確定在哪裏以及如何執行此檢查。 – Robert

回答

2

檢查您prepareForSegue

if segue.identifier == "logOutSegue" //執行註銷邏輯

+0

米沙!你搖滾! :) 非常感謝! – Robert