ma1*_*w28 1 enums switch-statement uitableview ios swift
为了使我的代码更具可读性和可维护性,Int
在带有类型为控件的switch语句中的案例标签中,使用标签代替硬编码的s 的最佳方法是什么Int
?
例如,在我的内部SettingsTableViewController
,我尝试过
enum Section : Int {
case Phone
case LogOut
case DeleteAccount
}
Run Code Online (Sandbox Code Playgroud)
和在 – tableView:didSelectRowAtIndexPath:
switch indexPath.section {
case .Phone:
// Push EditPhoneViewController
case .LogOut:
// Log out
case .DeleteAccount:
// Present action-sheet confirmation
}
Run Code Online (Sandbox Code Playgroud)
但是得到了编译错误
Enum case pattern cannot match values of the non-enum type 'Int'
Run Code Online (Sandbox Code Playgroud)
在开关中,您不能简单地使用indexPath.section
它,因为它与您的枚举类型不同。
使用 switch Section(rawValue: indexPath.section)!
归档时间: |
|
查看次数: |
916 次 |
最近记录: |