【发布时间】:2020-09-26 09:34:38
【问题描述】:
问题说明:我想 dequeueReusableCell "PromotionCellIdentifier" 任何地方的单元格 indexPath.row == 4 * n 但它只运行 dequeueReusableCell "PromotionCellIdentifier" 一次。我需要一个解决方案。
它只有一次 dequeueReusableCell "PromotionCellIdentifier" 因为 n == 1 不递增 += 1
我尝试了什么:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let homeSection = Section(rawValue: indexPath.section)!
var n = 1
switch homeSection {
case .Promotion:
let cell = tableView.dequeueReusableCell(withIdentifier: "",
for: indexPath)
return cell
case .Information:
if indexPath.row == 4 * n{
let cell = tableView.dequeueReusableCell(withIdentifier: "PromotionCellIdentifier",
for: indexPath)
n += 1
return cell
}
let cell = tableView.dequeueReusableCell(withIdentifier: "MenuItemCellIdentifier",
for: indexPath) as! MenuTableViewCell
let index = indexPath.row != 0 ? indexPath.row - 1 : 0
let menu = menuItems[index]
let number = menu.like
let stringNumber = numberdecimal(number: number)
cell.configure(imageName: menu.imageName, title: menu.name, detail: menu.details, like: stringNumber,nameLike: menu.likeImage)
return cell
}
}
所需输出: I want to implement in this way
我的输出: This is my result 1 & This is my result 2
我需要:
adjust row
adjust row
adjust row
adjust row
promotion row
adjust row
adjust row
adjust row
adjust row
promotion row
adjust row
adjust row
adjust row
adjust row
【问题讨论】:
标签: swift uitableview switch-statement increment indexpath