ios - UItableview 有两组选项
问题描述
我有一个表格视图,根据用户类型显示的内容略有不同。所以一个是狗主人的选项列表,另一个是遛狗者的选项列表。有些选项是相同的。最好的方法是一个表视图控制器?
Name
Address
My walkers
My dogs
Name
Address
My customers
Walking qualifications
(在现实生活中,这些表要长得多)
解决方案
创建两个不同的 tableview 单元格并根据用户类型更改单元格。这是一种做法。
func tableView(_ tableView: UITableView, cellForItemAt indexPath: IndexPath) -> UITableViewCell {
if dataSource[indexPath.item].isFirstuser {
let cell = tableview.dequeueReusableCell(withReuseIdentifier: “type1”, for: indexPath) as! type1Cell
let model = dataSource[indexPath.item]
cell.model = model
return cell
} else {
let cell = tableView.dequeueReusableCell(withReuseIdentifier: “type2”, for: indexPath) as! type2Cell
let model = dataSource[indexPath.item]
cell.model = model
return cell
}
}
推荐阅读
- php - 127.0.0.1 重定向你太多次
- angular - 类型“any [] | undefined”不能分配给类型“any []”
- h2 - 在 H2 数据库中插入行哈希
- javascript - 在 ImageBackground 中添加要要求的变量
- wireless - LAN 上的无线显示
- c# - C# .net core 3.1 访问 Json 元素
- java - 在不使用集合的情况下过滤 java 流以获取可根据属性区分的不同对象
- javascript - 获取 lodash-es/lodash 类型/文档的正确方法
- ios - 嵌套在 UITableViewCell 中的 UITableViewCell 的自动维度
- javascript - Azure Idendity 平台重定向到主页,ensureAuth 失败