我想将所选单元格中的字符串(arrat basicPhrases 的一部分)放入变量 (selectedBPhrase),然后我想执行 segue BasicPhrases2Phrase 并让它自己显示字符串。我怎么做?我很确定它与使用 didSelectRowAtIndexPath 有关,但我不确定。
这是我的代码:
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
}
我想它在这里,但不确定。
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
performSegueWithIdentifier("BasicPhrases2Phrase", sender: self)
}
}
提前感谢您的帮助。
最佳答案
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
selectedBPhrase = basicPhrases[indexPath.row]
performSegueWithIdentifier("BasicPhrases2Phrase", sender: self)
}
关于ios - 如何使用 UITableView Swift 将数组中的字符串放入变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36112913/