gpt4 book ai didi

Swift 3 UITableView 部分显示在列表后面

转载 作者:行者123 更新时间:2023-11-30 12:28:57 26 4
gpt4 key购买 nike

我正在尝试使用 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)"
}

screenshot

最佳答案

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

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

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

关于Swift 3 UITableView 部分显示在列表后面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43822677/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com