I have a ViewController with tableview called BasicPhrasesVC and I want to pass the data in the selected cell to display it on the next ViewController (called BasicPhrasesVC
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
selectedBasicPhrase = basicPhrases[indexPath.row]
self.performSegueWithIdentifier("BasicPhrasesVC2BasicDisplayVC", sender: selectedBasicPhrase)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "BasicPhrasesVC2BasicDisplayVC" {
if let nextVC = segue.destinationViewController as? NextViewController {
nextVC.selectedBasicPhrase = sender
}
}
}
Check segue name than take destinationViewController
and send you're data to it.
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
if (segue.identifier == "BasicPhrasesVC2BasicDisplayVC") {
let viewController:ViewController = segue!.destinationViewController as ViewController
viewController.selectedBasicPhrase = "Test phrase"
}
}
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
if (segue.identifier == "<segue name>") {
// pass the data
}
}