ahm*_*med 5 uitableview ios swift
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if tableView == table1{
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! acntTableViewCell
cell.account.text = account[indexPath.row].email
return cell
}
else if tableView == table2 {
let cell2 = tableView.dequeueReusableCell(withIdentifier: "cell2")
as! popTableViewCell
cell2.pop.text = pop[indexPath.row].answer
return cell2
}
}//its give me error here Missing return in function
Run Code Online (Sandbox Code Playgroud)
我将在一个视图控制器中填充两个不同的表。当我返回单元格时,它给我错误我做错的函数中缺少返回值,任何人都可以告诉我这段代码有什么问题
首先,您应该使用===
(references) 而不是==
.
这是断言失败是告诉编译器不存在其他函数方式的好方法的情况之一,例如:
if tableView === table1 {
return ...
} else if tableView === table2 {
return ...
} else {
fatalError("Invalid table")
}
Run Code Online (Sandbox Code Playgroud)
您还可以使用switch
:
switch tableView {
case table1:
return ...
case table2:
return ...
default:
fatalError("Invalid table")
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6239 次 |
最近记录: |