iOS Apprentice v5.0 - LocationDetailsViewController.swift - numberOfRowsInSection/numberOfSections

I didn’t see a general errata post for v5.0, so I’m creating a new post.

In the section that begins on page 89 I don’t see anything about overriding these methods, these are my trivial implementations:

  override func numberOfSections(in tableView: UITableView) -> Int {
    // #warning Incomplete implementation, return the number of sections
    return 3
  }
  
  override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    var rowCount = 0
    if section == 0 {
      rowCount = 2
    } else if section == 1 {
      rowCount = 1
    } else if section == 2 {
      rowCount = 4
    }
    return rowCount
  }

Without overriding these methods I couldn’t get any rows to show up in my tableview, perhaps there’s a setting in UITableView’s properties inspector that allows you to skip the overrides and just depend on the storyboard?

Note: fixed a bug - was only returning 2 rows instead of 4 for section 2

It is a static table view, so you don’t need these data source methods – you can design the entire thing in Interface Builder and it should just work, without having to write any code.