ios - 如何使用 UITableView Swift 将数组中的字符串放入变量中

标签 ios swift uitableview

我想将所选单元格中的字符串(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/

相关文章:

ios - 从本地文件获取对象中数据的问题

iphone - 将应用程序功能分配给 iOS 中的静音/静音开关

ios - 获取 AVAudioPlayer 一次播放多种声音

ios - 使用 Storyboard 以编程方式设置初始 View Controller

ios - Facebook 原生广告在滚动后无法在 UITableView 单元格中再次点击

ios - 点击单元格时表格 View 单元格会更改高度

ios - 如何修复 swift 4 中的 UITableView 单元格重复

ios - setSelectionIndicatorImage 尺寸错误

iOS8:IScreen.mainScreen().bounds 无法可靠地用于方向更改。建议?

ios - 确保 AM/PM(期间)不会出现在 NSDateFormat stringFromDate 中