How to properly implement a static cell with Swift 3

It's much easier if the table view contains only static cells:

  • In Interface Builder select the table view and set the Content to Static Cells
  • Create IBOutlets and IBActions in the controller class and connect them.
  • Implementing table view data source methods and subclassing cells is not needed.

So you can do the following. Set your table view, then make the cells static, once you've done that, you need to make sure you know how many sections you are going to have. This depends on your design or what you want to achieve.

Then you can do something like this:

If you have more than one section, and section 1 has more than one cell. And section 2 has only one cell.

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    switch indexPath.section {
    case 1:
        switch indexPath.row {
        case 0:
            // Do something
        case 1:
            // Do something 
        default:
            break
        }
    case 2:
        // Do something
    default:
        break
    }
}

If you have only one section with two cells you can do something like:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    switch indexPath.row {
    case 0:
        // Do something
    case 1:
        // Do something
    default:
        break
    }
}

I hope this helps to solve your problem. Good luck