轻按Tableview单元格时显示操作表

Cod*_*221 0 uitableview ios swift

然后我尝试在轻按单元格时调用操作表,这就是我所做的

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        let alertController = UIAlertController(title: "Action Sheet", message: "What do you like to do", preferredStyle: .alert)

        let okButton = UIAlertAction(title: "Done", style: .default, handler: { (action) -> Void in
            print("Ok button tapped")
        })

        let deleteButton = UIAlertAction(title: "Skip", style: .destructive, handler: { (action) -> Void in
            print("Delete button tapped")
        })

    alertController.addAction(okButton)
}
Run Code Online (Sandbox Code Playgroud)

当我点击单元格时,警报控制器未显示。我想念什么?

Jon*_*s W 5

您deleteButton快到了,请确保还添加-action并显示alertController使用情况present(alertController, animated: true, completion: nil)