小编Sam*_*ras的帖子

UITableView didSelectRow返回错误的行索引值

当我选择一行时,它会返回一个更大或更小的行索引值,但从不返回正确的值.如图所示,我选择了14回16.

选中14回16

这是我使用的代码:

  @IBOutlet var cheatTable: UITableView!

  let cheetSheet = ["one", "two", "three", "four", "five"]
  override func viewDidLoad() {
    super.viewDidLoad()
    cheatTable.delegate = self
    cheatTable.dataSource = self
  }

  func numberOfSections(in tableView: UITableView) -> Int {
    return 1
  }

  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 30
  }

  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "reuseID")!
    let text:String = "\(indexPath.row)"
    cell.textLabel?.text = text
    return cell
  }

  func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: …
Run Code Online (Sandbox Code Playgroud)

uitableview swift

1
推荐指数
1
解决办法
525
查看次数

标签 统计

swift ×1

uitableview ×1