Добавить свойства раздела и строки в перечисление следующим образом
enum MenuType: Int, CaseIterable, CustomStringConvertible {
//section 1
case plan, documentation, visitlist, document, constructdiary, plancorrection
//section 2
case sync, settings, info
var section: Int {
switch self {
case .plan,.documentation,.visitlist,.document,.constructdiary,.plancorrection: return 0
case .sync,.settings,.info: return 1
}
}
var row: Int? {
switch self.section {
case 0: return self.rawValue
case 1: return self.rawValue - MenuType.allCases.filter { $0.section < self.section }.count
default: return nil
}
}
var description: String {
switch self {
case .plan: return "plan"
case .documentation: return "documentation"
case .visitlist: return "visitlist"
case .document: return "document"
case .constructdiary: return "constructdiary"
case .plancorrection: return "plancorrection"
case .sync: return "sync"
case .settings: return "settings"
case .info: return "info"
}
}
}
Вы можете получить выбранный тип меню, сравнив раздел indexPath и строку
class MenuViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
}
override func numberOfSections(in tableView: UITableView) -> Int {
return Array(Set(MenuType.allCases.map { $0.section })).count
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return MenuType.allCases.filter{ $0.section == section }.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .default, reuseIdentifier: "Cell")//tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
let type = MenuType.allCases.first(where: { $0.section == indexPath.section && $0.row == indexPath.row })
cell.textLabel?.text = type?.description
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let selectedMenuType = MenuType.allCases.first(where: { $0.section == indexPath.section && $0.row == indexPath.row })
}
}