swift - Swift:TableView didSelectRowAt 仅针对某些行触发?
问题描述
我目前正在向我的设置表视图添加功能,并且由于某种原因,表视图 didSelectRowAt 函数仅在我选择每个部分的第一行时才会触发。
我使用枚举设置了表格视图,但我不明白为什么会导致问题。
这是我的 didSelectRowAtFunction:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard let section = SettingsSections(rawValue: indexPath.section) else { return }
guard let accountSection = AccountOptions(rawValue: indexPath.row) else { return }
guard let financialSection = PaymentOptions(rawValue: indexPath.row) else { return }
guard let communicationsSection = CommunicationsOptions(rawValue: indexPath.row) else { return }
switch section {
case .Account:
switch accountSection {
case .editAccountInfor:
print("Edit account pressed")
case .logout:
print("logout pressed")
}
case .Communications:
switch communicationsSection {
case .notifacations:
print("notifs pressed")
}
case .Financial:
switch financialSection {
case .linkBankAccount:
print("LBA pressed")
case .viewPaymentOptions:
print("payment options pressed")
}
}
}
当我按下编辑账户信息行、链接银行账户行或通知行时,它完全可以触发。但是,当我按下该部分中不是第一行的任何行时,它不会显示任何语句。
以防万一,这是我的 SettingsSections 代码以及 AccountOptions 让你们看看我是如何设置的。
enum SettingsSections: Int, CaseIterable, SectionType {
case Account
case Financial
case Communications
var containsSwitch: Bool {
return false
}
var description: String {
switch self {
case .Account: return "Account"
case .Financial: return "Financial"
case .Communications: return "Communications"
}
}
}
enum AccountOptions: Int, CaseIterable, SectionType {
case editAccountInfor
case logout
var containsSwitch: Bool {
return false
}
var description: String {
switch self {
case .editAccountInfor: return "Edit Account Information"
case .logout: return "Log Out"
}
}
}
解决方案
推荐阅读
- c++ - 当应用程序在 Windows 上使用 mingw 构建时,如何防止 Qt 提供的 Zlib 的 deflateend(&compr_str) 函数出现段错误?
- reactjs - 有没有办法我可以通过 useReducer 和 Context API 访问组件的状态到另一个组件?
- python - Python从一个列表创建多个文件夹
- algorithm - 如何最大化两个变量函数?
- python - Python正则表达式将字符串与点匹配
- java - 有没有办法一起添加 2 个或多个 switch 语句
- opengl - 具有平均法线的高度场
- asp.net-core - 无法将我的项目定位到 .NET Core 5.0
- r - 合并后维护概览脚注
- javascript - 如何捕获复选框是否已被选中?