I have a ViewController with a table view called BasicPhrasesVC, and I want to transfer the data in the selected cell to display it on the next ViewController (called BasicPhrasesVC).
class BasicPhrasesVC: UIViewController, UITableViewDataSource, UITableViewDelegate { let basicPhrases = ["Hello.","Goodbye.","Yes.","No.","I don't understand.","Please?","Thank you.","I don't know."] var selectedBasicPhrase = "" func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return basicPhrases.count } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell")! cell.textLabel?.text = basicPhrases[indexPath.row] return cell } override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
I'm not sure what to do (I want to pass the variable "selectedBasicPhrase")
} func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { selectedBasicPhrase = basicPhrases[indexPath.row] performSegueWithIdentifier("BasicPhrasesVC2BasicDisplayVC", sender: self) } }
Any help is appreciated.
source share