根据 JSON 条件将复选标记应用于某些表视图行



我正在尝试创建一个条件语句,用于确定 tableView 记录是否将显示复选标记附件。

如果满足条件,则复选标记应自动应用于相应的记录。

以下是我的单元格ForRowAt中的内容:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.selectionStyle = UITableViewCell.SelectionStyle.none

JSON 结构定义如下:

var structure = [JSONStructure]()
struct JSONStructure: Codable {
var peron: String
var update: Int
}

JSON 会将更新显示为数字 100 或 200。 如果update等于 100,则应为该记录显示复选标记

但是,如果记录的update等于 200,则不应显示该记录的复选标记。

这样的事情能完成吗?

到目前为止,你做了什么?

这可以使用cellForRowAtIndexPath中的简单条件来完成

if (update == 100) {
cell.accessoryType = .checkmark
} else {
cell.accessoryType = .none
}

最新更新