0

I want to put the string from whichever cell is chosen (part of the arrat basicPhrases) into a variable (selectedBPhrase) then I want to perform the segue BasicPhrases2Phrase and have it display the string by itself. How do I do that? I'm pretty sure it has something to do with using didSelectRowAtIndexPath but I'm not sure.

This is my code:

import UIKit

class BasicPhrases: UITableViewController {

let basicPhrases = ["Hello.","Goodbye.","Yes.","No.","I don't understand.","Please?","Thank you.","I don't know."]
var selectedBPhrase = ""

override func viewDidLoad() {
    super.viewDidLoad()

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return basicPhrases.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell")!
    cell.textLabel?.text = basicPhrases[indexPath.row]
    return cell
}

I think it's in here but not sure.

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    performSegueWithIdentifier("BasicPhrases2Phrase", sender: self)
}
}

Thanks for any help in advance.

2 Answers 2

3
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
 {
      selectedBPhrase =  basicPhrases[indexPath.row]
     performSegueWithIdentifier("BasicPhrases2Phrase", sender: self)
}
Sign up to request clarification or add additional context in comments.

Comments

0

You need to get UIViewTableCell from indexPath, as in cellForRowAtIndexPath, as in didSelectRowAtIndexPath.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.