对于将开关语句使用到UITableView,我有些困惑。我试图设置我的numberOfRowsInSection函数,但是我的开关语句“二进制运算符'~=‘不能应用于'Bool’和‘Int’类型的操作数时出错:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch section {
case section == 0:
return provinces.count
case section == 1:
return territories.count
default:
return 0
}
}我很困惑,因为节被声明为Int,但是这个错误似乎表明它是一个BOOL。当我使用if- use语句时,它编译得很好:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return provinces.count
} else {
return territories.count
}
}我遗漏了什么?
发布于 2015-06-20 21:07:06
删除section ==
switch section {
case 0:
return provinces.count
case 1:
return territories.count
default:
return 0
}这些案例代表了section的值。但是您的代码没有意义,因为这些情况将被求值为true或false,这是部分不可能的值。这些值将是bools,因此错误消息将讨论bools。
https://stackoverflow.com/questions/30958863
复制相似问题