Ios 表视图中的单元格没有响应
我正在处理一个待办事项列表应用程序,每当我在Ios 表视图中的单元格没有响应,ios,swift,xcode,Ios,Swift,Xcode,我正在处理一个待办事项列表应用程序,每当我在模拟器上运行它,并尝试打印我的数组中的项目时,其他单元格项目就会打印出来 这是我的密码: import UIKit class TodoListViewController: UITableViewController { let itemArray = ["math","english"] override func viewDidLoad() { super.viewDidLoad() // Do
模拟器上运行它,并尝试打印我的数组中的项目时,其他单元格项目就会打印出来
这是我的密码:
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
而不是didSelectRowAt
,后者是在您选择一行时触发的,这样您就可以从上一个选定行获得打印
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print(itemArray[indexPath.row])
}