【发布时间】:2019-06-07 15:34:27
【问题描述】:
我有一个包含 2 个原型单元格和 2 个自定义类的表格视图。 在第一个单元格中,我有一个图像视图,在第二个单元格中,我有一个标签。 这是我的代码,图像是结果: 我希望它是这样的:图像单元格 - 标签单元格 - 图像单元格 - 标签单元格
var categories = ["first ","second", "third", "forth"]
var banners = ["close-envelope","chat"]
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0{
return banners.count
}else{
return categories.count
}
}
func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let bannerCell = tableView.dequeueReusableCell(withIdentifier: "bannerCell", for: indexPath) as! bannerCell
let catCell = tableView.dequeueReusableCell(withIdentifier: "categoryCell", for: indexPath) as! categoryCell
if indexPath.section == 0{
bannerCell.banner.image = UIImage(named: banners[indexPath.row])
return bannerCell
}else{
catCell.lbl.text = categories[indexPath.row]
catCell.btn.setTitle(categories[indexPath.row], for: .normal)
return catCell
}
}
@IBOutlet weak var tableview:UITableView!
代码输出:
【问题讨论】:
-
@Sh_Khan 对不起我添加了
-
@Sh_Khan 请看图片,我不想要它,我想要它显示图像单元-标签单元-图像单元。但正如您在图片中看到的那样,它是图像单元 - 图像单元 - 标签单元
-
@Sh_Khan 如果我不需要 2 部分,我该如何实现?