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
我将在一个 View Controller 中填充两个不同的表。当我返回单元格时它给我错误 Missing return in function where I doing wrong anyone can suggest me what wrong with this code
最佳答案
首先,您应该使用 ===
(引用)而不是 ==
来比较表。
这是断言失败是告诉编译器该函数不存在其他方式的好方法的一种情况,例如:
if tableView === table1 {
return ...
} else if tableView === table2 {
return ...
} else {
fatalError("Invalid table")
}
您还可以使用开关
:
switch tableView {
case table1:
return ...
case table2:
return ...
default:
fatalError("Invalid table")
}
关于ios - 我如何在 swift 3 的一个 View Controller 中填充两个不同的 TableView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48084210/