ios - 我如何在 swift 3 的一个 View Controller 中填充两个不同的 TableView

标签 ios swift uitableview

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/

相关文章:

ios - objective-c 区分 applicationWillResignActive 中的警报消息和任务切换器

ios - 如何从 Xcode 8 中删除坏证书?

ios - 如何在 SwiftUI View 中访问自己的窗口?

swift - 共享扩展 : Grab thumbnail in custom view controller like SLComposeServiceViewController

ios - SwiftUI:iPad 上不需要的 Split View

ios - 为什么标签永远不会出现在我的 UITableViewCell 子类中?

ios - 单击 UIButton 后如何更改 UITableviewCell 标签文本?

ios - 在单行 UILabel 旁边居中 NSTextAttachment 图像

ios - UIScrollView 优于 MKMapView

ios - 如何将 TableViewCell 值传递给 Swift 3.0 中的新 ViewController?