How to properly implement a static cell using Swift 3

I literally could not find a single tutorial that would show me how to create an application that uses static cells; with interactive cells. Based on the few published and object answers, I put something together. My problem is that when I click on a cell, I get staticDemoTableCellno member present.

I have embedded the table controller in my UIViewController. For this cell (only so far) I created a class:

class staticDemoTableCell: UITableViewCell, UITableViewDelegate {
  @IBOutlet weak var tableView: UITableView! 

  override func awakeFromNib() {
    [...]
    tableView.delegate = self
  }

  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    print("clicked") // Works when the cell is clicked
    // self.present() do not work. I need to present another viewcontroller when this cell is clicked
  }

}

Something does not fit, for each cell - a class?

, . , , . , : : , : .. , iOS. .

+4
2

, :

  • Interface Builder Content Static Cells
  • IBOutlet IBAction .
  • .
+8

, . , , , , , . , .

- :

, 1 . 2 .

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

, - :

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

, . .

+5

Source: https://habr.com/ru/post/1666822/


All Articles