Swift 单击UITableViewCell时
我有一个表视图单元格,可以单击,但目前什么也不做。我怎样才能采取行动呢?单击单元格时执行某些操作。例如,我如何显示一个警报窗口,该窗口在单击单元格后会记录密码?有几种方法,但是我建议使用Swift 单击UITableViewCell时,swift,uitableview,uialertview,tableviewcell,Swift,Uitableview,Uialertview,Tableviewcell,我有一个表视图单元格,可以单击,但目前什么也不做。我怎样才能采取行动呢?单击单元格时执行某些操作。例如,我如何显示一个警报窗口,该窗口在单击单元格后会记录密码?有几种方法,但是我建议使用UITableViewDelegate方法didSelectRowAt。一个快速的例子是: override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let alertContr
UITableViewDelegate
方法didSelectRowAt
。一个快速的例子是:
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)
}
有几种方法可以做到这一点,但是我建议使用
UITableViewDelegate
方法didSelectRowAt
。一个快速的例子是:
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)
}
DidSelectedRowatIndeXPath委托方法为您执行此操作。DidSelectedRowatIndeXPath委托方法为您执行此操作。