Joseph Michael Pesch
VP Programming

Swift IOS UITableViewCell Button

by 5. January 2019 12:40

There are two steps to add a working button to a table view cell. The first step is to add a button like this:

cell.accessoryType = .detailDisclosureButton

The second step is to take action when the button is tapped by creating the accessoryButtonTappedForRowWith method:

override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
    doSomethingWithItem(indexPath.row)
}

Tags:

XCode | iOS | Swift