【发布时间】:2017-07-19 10:48:41
【问题描述】:
我已经为不同的单元格标识符创建了一个结构:
enum CustomCellIdentifiers
{
static let cellForCountry = "cellForCountry"
static let cellForCity = "cellForCity"
static let cellForStoreType = "cellForStoreType"
}
并且我正在按照 switch case 将单元格注册到表格中,例如:
view.tableForItems.register(UINib.init(nibName: cellIdentifier, bundle: nil), forCellReuseIdentifier:cellIdentifier)
但是当我注册单元格时,我得到了reuseIdentifier 为 nil 的错误:
class CustomTableCell: UITableViewCell
{
override func awakeFromNib()
{
super.awakeFromNib()
// Initialization code
switch self.reuseIdentifier ?? "cellForCountry" //It only work with country cell
{
case CustomCellIdentifiers.cellForCountry:
print("cellForCountry") break;
case CustomCellIdentifiers.cellForCity:
print("cellForCity") break;
case CustomCellIdentifiers.cellForStoreType:
print("cellForStoreType")
break;
default: break
}
}
}
【问题讨论】:
-
如果您想存储简单的字符串并希望它是不可变的,请使用 enum 而不是 Struct。此外,开关盒中也不需要中断。
-
使用枚举代替struct来存储值。
-
@Jaydeep 我改变了,但重用标识符的问题是 nil
标签: swift uitableview