【发布时间】:2019-03-11 00:31:37
【问题描述】:
我有很多自定义单元格,并希望通过使用结构并将有关单元格的信息存储在数组中来简化 cellForRowAt。
struct HowToCells {
let helpCell: UITableViewCell
let identifier: String
let icon: UIImage
let cellName: String
}
var cellArray = [HowToCells]()
cellArray.append(HowToCells.init(helpCell: ScreenRecordingTableViewCell(), identifier: "ScreenRecordingTableViewCell", icon: HowToImage.screenRecording.image(), cellName: "Enable screen recording"))
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let c = cellArray[indexPath.row]
let cellToUse = c.helpCell
let cell = tableView.dequeueReusableCell(withIdentifier: c.identifier, for: indexPath) as! cellToUse
}
我收到以下错误:使用未声明的类型“cellToUse”
ScreenRecordingTableViewCell 是一个自定义的 UITableViewCell
【问题讨论】:
-
这正是引入重用单元的原因:将不可见的单元保持在内存中......
-
“想通过使用结构体来简化 cellForRowAt 并将有关单元格的信息存储在数组中。” 然后将信息存储在数组中,而不是单元格本身,这顺便说一句,你必须做任何事情才能让桌子工作!
-
@RakeshaShastri -
ScreenRecordingTableViewCell在这种情况下是实际的单元格,它被存储在数组中。
标签: swift uitableview cell subclass