我有一个来自一个ViewController的segue。
当点击LogOut按钮(转到LogIn ViewController)时,一个应该运行(现在崩溃),另一个运行(工作正常)点击缩略图一段视频。
由于我需要从服务器检索视频并将其显示在我正前往(WatchVideoViewController)的ViewController中,我会执行以下代码:
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
}
正如您可能猜到这个代码在执行每个segue时运行,这就是我的LogOut segue崩溃的原因。
Could not cast value of type 'AppName.LoginViewController' to 'Appname.WatchVideoViewController'.
以下是我称之为segues的代码片段:
@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)
}
调用pressLogOutButton时有没有办法避免运行prepareForSegue?非常感谢!
答案 0 :(得分:2)
检入prepareForSegue
if segue.identifier == "logOutSegue"
//执行注销逻辑