我的 UITableView 有两个部分,所以我为它们创建了一个枚举:
private enum TableSections {
HorizontalSection,
VerticalSection
}
如何使用在 numberOfRowsInSection 委托方法中传递的“section”变量进行切换?看来我需要将“section”转换为我的枚举类型?或者有更好的方法来实现这一点吗?
错误是“在类型‘int’中找不到枚举案例‘HorizontalSection’。
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch section {
case .HorizontalSection:
return firstArray.count
case .VerticalSection:
return secondArray.count
default
return 0
}
}
为了做到这一点,你需要给你的枚举一个类型(在本例中为 Int):
private enum TableSection: Int {
horizontalSection,
verticalSection
}
这使得“horizontalSection”将被分配值 0,而“verticalSection”将被分配值 1。
现在在你的numberOfRowsInSection
你需要使用的方法.rawValue
在枚举属性上以访问它们的整数值:
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch section {
case TableSection.horizontalSection.rawValue:
return firstArray.count
case TableSection.verticalSection.rawValue:
return secondArray.count
default:
return 0
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)