【发布时间】:2019-06-06 12:24:21
【问题描述】:
我想在 tableView 中选择一行。 但是
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch indexPath.section {
case 0:
switch indexPath.row {
case 0:
...
}
...
}
这个我想迭代
private enum Section {
case section0
case section1
...
}
private enum Section0 {
case section0row0
case section0row1
...
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch Section(rawValue: indexPath.section)! {
case .section0:
switch Section0(rawValue: indexPath.row)! {
case section0row0:
...
}
...
}
像这样。
也许有更好的方法来编码枚举... 有人能告诉我一个非常聪明的解决方案吗?
谢谢:)
【问题讨论】:
-
你先告诉我们你的用例怎么样 - 你到底想做什么?肯定有比你正在做的更好的方法。
-
同意 mag_zbc,你应该给我们一个上下文来理解哪个是最好的解决方案。例如,您的主要目标是什么?您的表格视图是静态的还是动态的?您的数据源是如何构建的?
-
对节使用枚举是可以的。对于行,它有点令人困惑。为什么要硬编码要处理的行数?如果您的所有内容都是硬编码的,只需在情节提要中进行,而无需完全编写代码!