Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 单击UITableViewCell时_Swift_Uitableview_Uialertview_Tableviewcell - Fatal编程技术网

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委托方法为您执行此操作。