深入探索JSON文件在iOS应用中的使用
1. 表格视图单元格选择逻辑优化
在 tableView(_:cellForRowAt:) 方法里,要在设置单元格 textLabel 属性文本的那行代码之后调用 set(selected:at:) 方法。以下是修改后的 tableView(_:cellForRowAt:) 方法代码:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)
-> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier:
"locationCell", for: indexPath) as
UITableViewCell
cell.textLabel?.text =
manager.locationItem(at:indexPath).full
set(selected: cell, at: indexPath)
return cell
}
这样做的话, set(selected:at:) 方法会针对表格视图中的每一行进行调用,并且只有包含所选位置的那一行会显示选中标记。构建并运行项目后,现在应该只能选择一个位置了。要是选择了另一个位置,之前选择的位置就会取消选中。
超级会员免费看
订阅专栏 解锁全文
971

被折叠的 条评论
为什么被折叠?



