【发布时间】:2020-03-16 04:29:48
【问题描述】:
这里我想在我的表格视图中将这些数据显示为两个部分,我有来自模型的以下数组。
在这里,我将整个数据放入一个模型中,并且两者都在顶部可见。
var TotalbooksList : [BooksList]!
var RecomendBooks : [BooksList]!
var tableData: [(title: String, list: [BooksList]?)] {
return [(title: "Recomended Books", list: RecomendBooks),
(title: "Total Books", list: TotalbooksList)]
}
我编写了以下委托方法,但我没有将数据放入第二部分
func numberOfSections(in tableView: UITableView) -> Int {
return self.tableData.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tableData[section].list?.count ?? 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "RecomandBookTVCell", for: indexPath)as!RecomandBookTVCell
if let data = self.tableData[indexPath.section].list, data.count > 0 {
let model = data[indexPath.row]
cell.selectionStyle = .none
cell.booktitle.text = model.title ?? ""
cell.bookAuthor.text = model.author ?? ""
if model.photo != ""{
cell.bookimage.sd_setImage(with: URL(string: Services.BaseURL + (model.photo ?? "")), placeholderImage: UIImage(named: ""))
}
cell.genrelbl.text = model.genre ?? ""
cell.addlog.tag = indexPath.row
cell.addlog.addTarget(self, action: #selector(addLog(sender:)), for: .touchUpInside)
}
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 150
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 50
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
tableData[section].title
}
【问题讨论】:
-
放置一些断点并进行调试。它会帮助你
标签: ios swift tableview sections