У меня есть UITableViewController
, который отображает количество строк, содержащих пользовательские типы UITableViewCell
Ячейки разделены на 2 категории, а затем еще 3 подкатегории.
система> текст / мультимедиа / интерактив
пользователь> текст / мультимедиа / интерактивный
В настоящее время я использую переключатель с вложенным переключателем для назначения правильного типа ячейки.
Это, однако, выглядит не очень хорошо.Не думаю, что это лучший способ добиться этого, но я не уверен, как еще подойти к этому.
Я не использую раскадровки.
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let item = viewModel.history[indexPath.row]
switch item.origin {
case .system:
switch item.type {
case .text:
let cell = tableView.dequeueReusableCell(withClass: BotMessageCell.self)
cell.setContent(as: item)
cell.layoutSubviews()
return cell
case .media:
let cell = tableView.dequeueReusableCell(withClass: BotMediaCell.self)
cell.setContent(as: item)
cell.layoutSubviews()
return cell
case .interactive
let cell = tableView.dequeueReusableCell(withClass: BotInteractiveCell.self)
cell.setContent(as: item)
cell.layoutSubviews()
return cell
default:
fatalError("No dequeueReusableCell availble for cell of type \(item.type) ")
}
case .user:
switch item.type {
case .text:
let cell = tableView.dequeueReusableCell(withClass: UserMessageCell.self)
cell.setContent(as: item)
cell.layoutSubviews()
return cell
case .media:
let cell = tableView.dequeueReusableCell(withClass: UserMediaCell.self)
cell.setContent(as: item)
cell.layoutSubviews()
return cell
case .interactive
let cell = tableView.dequeueReusableCell(withClass: UserInteractiveCell.self)
cell.setContent(as: item)
cell.layoutSubviews()
return cell
default:
fatalError("No dequeueReusableCell availble for cell of type \(item.type) ")
}
}
}