单击 UITableViewCell 时
When a UITableViewCell is clicked
我有一个 table 可点击的视图单元格,但目前什么都不做。我怎样才能采取行动呢?单击单元格时执行某些操作。例如,如何显示一个警报 window,在单击单元格后输入密码?
有几种方法可以做到这一点,但我建议使用 UITableViewDelegate
方法 didSelectRowAt
。 swift 示例为:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let alertController = UIAlertController(title: "Title Here", message: "Message Here", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Okay", style: .default, handler: nil))
present(alertController, animated: true, completion: nil)
}
我有一个 table 可点击的视图单元格,但目前什么都不做。我怎样才能采取行动呢?单击单元格时执行某些操作。例如,如何显示一个警报 window,在单击单元格后输入密码?
有几种方法可以做到这一点,但我建议使用 UITableViewDelegate
方法 didSelectRowAt
。 swift 示例为:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let alertController = UIAlertController(title: "Title Here", message: "Message Here", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Okay", style: .default, handler: nil))
present(alertController, animated: true, completion: nil)
}