0

I'm trying to create a list of products using swift 3 UITableViewController, but the sections is showing after the list of the products. There must be something I'm missing, couldn't find anywhere

Here is a simplified code

let data = [["0,0", "0,1", "0,2"], ["1,0", "1,1", "1,2"], ["2,0", "2,1", "2,2"],  ["3,0", "3,1", "3,2"]]

override func numberOfSections(in tableView: UITableView) -> Int {
    return data.count//productCategoriesSections.count
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return data[section].count//productCategories[section].count
}


 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "defaultCategoryCell", for: indexPath) as! CategoryDefaultTableViewCell
    cell.titleTextView.text = data[indexPath.section][indexPath.row]
    return cell
 }

override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
    return "Section \(section)"
}

screenshot

ericknmp
  • 3
  • 3

1 Answers1

0

It is because you are using wrong callback.

Use override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? instead of override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String?.

The former will place the text as a header above the section. The latter places it at the bottom.

Mr. Hedgehog
  • 966
  • 4
  • 13