gpt4 book ai didi

iOS:TableView 中的多个部分不起作用

转载 作者:行者123 更新时间:2023-11-28 20:55:43 25 4
gpt4 key购买 nike

我正在开发一个应用程序,我需要在其中显示带有标题的多行。在我的例子中,只显示了一个部分。我搜索了所有内容,但找不到合适的解决方案。

这是我的代码:

class Timeline: UITableViewCell {
@IBOutlet weak var timelineData: UITextView!
}

class StudenTimelineViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

let section = ["pizza", "deep dish pizza", "calzone"]

let items = [["Margarita", "BBQ Chicken", "Peproni"], ["sausage", "meat lovers", "veggie lovers"], ["sausage", "chicken pesto", "prawns & mashrooms"]]

override func viewDidLoad() {
super.viewDidLoad()
}

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

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return section.count
}

func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return self.section[section]
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TimelineId", for: indexPath) as! Timeline
let gpsData = items[indexPath.section][indexPath.row]

cell.timelineData.text = gpsData
return cell
}

func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 40
}

我得到了什么 enter image description here

我将如何获得所有部分。提前致谢。

最佳答案

这是因为您的方法名称 func numberOfSectionsInTableView(tableView: UITableView) -> Int 不正确,因此未被调用。

func numberOfSections(in tableView: UITableView) -> Int 替换名称,看看奇迹发生了。

关于iOS:TableView 中的多个部分不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52621491/

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