Coder221 Coder221 - 1 month ago 10
iOS Question

Displaying action sheet when tableview cell is tapped

Then I am trying to call action sheet when cell is tapped, and this is what I did

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)
}


When i am tapping cell, alert controller is not showing up. What am I missing?

Answer

You're almost there, make sure you add your deleteButton-action as well and present the alertController using present(alertController, animated: true, completion: nil)

Comments