Ios 如何使用UITableView将数组中的字符串放入变量
我想将所选单元格中的字符串(arrat基本短语的一部分)放入变量(selectedBPhrase)中,然后我想执行segue基本短语2,并让它自己显示字符串。我该怎么做?我很确定这与使用DidSelectRowatineXpath有关,但我不确定Ios 如何使用UITableView将数组中的字符串放入变量,ios,swift,uitableview,Ios,Swift,Uitableview,我想将所选单元格中的字符串(arrat基本短语的一部分)放入变量(selectedBPhrase)中,然后我想执行segue基本短语2,并让它自己显示字符串。我该怎么做?我很确定这与使用DidSelectRowatineXpath有关,但我不确定 override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { performSegueWithIdentifi
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
performSegueWithIdentifier("BasicPhrases2Phrase", sender: self)
}
}
这是我的代码:
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)
}
}
感谢您提前提供的帮助。您需要从
indepath
获取UIViewTableCell
,如CellForRowatineXpath
,如DidSelectRowatineXpath您需要从Indepath
获取UIViewTableCell
,如CellForRowatineXpath
,正如在didselectRowatineXpath
中一样,重写函数表视图(表视图:UITableView,didselectRowatineXpath索引:NSIndexPath)
{
selectedBPhrase=basicPhrases[indexath.row]
performsguewithidentifier(“基本短语2”,发件人:self)
}
覆盖函数tableView(tableView:UITableView,didSelectRowAtIndexPath:nsindepath)
{
selectedBPhrase=basicPhrases[indexath.row]
performsguewithidentifier(“基本短语2”,发件人:self)
}