habed
habed

Reputation: 201

When a UITableViewCell is clicked

I have a table view cell that is clickable but at the moment does nothing. How can I put action to it? To do something when the cell is clicked. For example how can I display a alert window that takes a password filed once the cell is clicked?

Upvotes: 0

Views: 195

Answers (1)

Welton122
Welton122

Reputation: 1131

There are a few ways to do it, however I would reccommend using the UITableViewDelegate method didSelectRowAt. A swift example would be:

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

Upvotes: 3

Related Questions