表格视图中的单元格无响应 [英] Cells in table view not responding
本文介绍了表格视图中的单元格无响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用待办事项列表应用程序,每当在simulator
上运行它并尝试打印array
中的项目时,其他单元格项目都会被打印.
I am working on a todo list app and whenever I run it on the simulator
and try to print the items in my array
, the other cells item get printed.
这是我的代码:
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
,当您选择一行时会触发后者,以便您从上一选定的行中获取打印内容
You need didSelectRowAt
not didDeselectRowAt
, the latter is triggered when you select a row so you get the print from the previous selected row
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print(itemArray[indexPath.row])
}
这篇关于表格视图中的单元格无响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文