0

我正在尝试使用 swift 3 UITableViewController 创建产品列表,但这些部分显示在产品列表之后。一定有什么我错过了,在任何地方都找不到

这是一个简化的代码

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

截屏

4

1 回答 1

0

这是因为您使用了错误的回调。

使用override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?而不是override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String?.

前者会将文本作为标题放在该部分的上方。后者将其放在底部。

于 2017-05-06T16:19:18.493 回答