iOS:PrepareForSegue不工作

iOS:PrepareForSegue不工作,ios,swift,Ios,Swift,我在尝试将数据传递到其他一些视图控制器时遇到问题。我可以成功地执行segue,但我需要的补充数据无法通过segue override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){ /// Identify the row number let rowNumber = indexPath.row let section = indexPath.s

我在尝试将数据传递到其他一些视图控制器时遇到问题。我可以成功地执行segue,但我需要的补充数据无法通过segue

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
    /// Identify the row number
    let rowNumber = indexPath.row
    let section = indexPath.section


    // Obtain the array of model names for the selected auto maker
    let moviesForSelectedGenre: AnyObject? = dict_Genre_dict2[genres[section]]
    dict2_Movie_MovieInfo = moviesForSelectedGenre as! Dictionary
    let movieNumber:String = "\(rowNumber+1)"
    movie = dict2_Movie_MovieInfo[movieNumber] as! [String]
    youtubeID = movie[2]
    movieTitle = movie[0]

    performSegueWithIdentifier("showTrailer1", sender: self)
}

func add(sender: AnyObject) {
    performSegueWithIdentifier("addMovie", sender: self)
}

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
    if segue == "showTrailer1"{

        // Obtain the object reference of the destination view controller
        let trailerViewController: MovieTrailerViewController = segue.destinationViewController as! MovieTrailerViewController

        //Pass the data object to the destination view controller object
        trailerViewController.youTubeMovieTrailerID = youtubeID
        trailerViewController.movieTitle = movieTitle
    }
    else if segue == "addMovie"{
        let addMovieViewController: AddMovieViewController = segue.destinationViewController as! AddMovieViewController
        addMovieViewController.delegate = self
    }
}

如果有人能找出这一切发生的原因,那就太棒了。谢谢

你不是在和我比较

segue.identifier


segue
之后添加
.identifier
将解决您的问题。

prepareforsgue
中,您必须使用
segue.identifier
检查调用了哪个segue

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
    if segue.identifier == "showTrailer1"{

        // Obtain the object reference of the destination view controller
        let trailerViewController: MovieTrailerViewController = segue.destinationViewController as! MovieTrailerViewController

        //Pass the data object to the destination view controller object
        trailerViewController.youTubeMovieTrailerID = youtubeID
        trailerViewController.movieTitle = movieTitle
    }
    else if segue.identifier == "addMovie"{
        let addMovieViewController: AddMovieViewController = segue.destinationViewController as! AddMovieViewController
        addMovieViewController.delegate = self
    }
}

准备好segue的电话吗?您是否使用断点进行了测试?在方法之前添加
self.
。比如
self.performsguewithidentifier(“showtailer1”,发送者:self)
你能给我们看一下trailerViewController的代码吗?比较一下标识符,比如
segue.identifier==“showtailer1”
。我在凌晨2:30就开始做这件事,真是罪有应得。
else if segue == "addMovie"{
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
    if segue.identifier == "showTrailer1"{

        // Obtain the object reference of the destination view controller
        let trailerViewController: MovieTrailerViewController = segue.destinationViewController as! MovieTrailerViewController

        //Pass the data object to the destination view controller object
        trailerViewController.youTubeMovieTrailerID = youtubeID
        trailerViewController.movieTitle = movieTitle
    }
    else if segue.identifier == "addMovie"{
        let addMovieViewController: AddMovieViewController = segue.destinationViewController as! AddMovieViewController
        addMovieViewController.delegate = self
    }
}