【发布时间】:2018-01-24 05:22:09
【问题描述】:
我目前正在尝试复制您在图片中看到的数组:
我创建了一个自定义单元格类,以便显示标签和切换按钮。我不知道的部分是如何在每个单元格下方显示图例。
这是我目前的代码:
var options = ["Solstice", "Equinox", "Enable Snapshot"]
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return options.count
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as! CustomCell
let switchView = UISwitch(frame: CGRect.zero)
cell.addSubview(switchView)
cell.accessoryView = switchView
cell.nameLabel.text = options[indexPath.row]
return cell
}
图例可以是另一个自定义单元格,具有不同的样式吗?最好的方法是什么?
【问题讨论】:
-
使用两个表格视图单元格,一个用于带有开关的标签,另一个单元格是您的文本,并将其显示为奇偶数,或者您也可以根据您的显示要求执行条件代码。
-
cell.addSubview(switchView)不,这是个坏主意。导致重用问题以及将其设置为accessoryView。
标签: ios swift uitableview