gpt4 book ai didi

ios - 表格 View 中的单元格没有响应

转载 作者:搜寻专家 更新时间:2023-11-01 06:53:00 25 4
gpt4 key购买 nike

我正在开发一个待办事项列表应用程序,每当我在 模拟器 上运行它并尝试打印我的 array 中的项目时,其他单元格项目就会被打印出来。

这是我的代码:

import UIKit

class TodoListViewController: UITableViewController {
let itemArray = ["math","english"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
// DATASOURCE METHODS

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return itemArray.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ToDoItemCell", for: indexPath)
cell.textLabel?.text = itemArray[indexPath.row]
return cell
}

// DELEGATE METHODS

override func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
print(itemArray[indexPath.row])
}


}

最佳答案

您需要 didSelectRowAt 而不是 didDeselectRowAt ,后者在您选择一行时触发,以便您从上一个选定的行中获取打印内容

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print(itemArray[indexPath.row])
}

关于ios - 表格 View 中的单元格没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55869112/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com