Rav*_*avi 1 uitableview ios swift
我正在开发一个应用程序,我需要在其中显示带有标题的多行。就我而言,仅显示一个部分。我已经搜索了所有内容但找不到合适的解决方案。
Here is my code:
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
}
Run Code Online (Sandbox Code Playgroud)
我将如何获得所有部分。提前致谢。
这是因为您的方法名称func numberOfSectionsInTableView(tableView: UITableView) -> Int不正确,因此未被调用。
将名称替换为func numberOfSections(in tableView: UITableView) -> Int,然后看看奇迹发生。
| 归档时间: |
|
| 查看次数: |
795 次 |
| 最近记录: |