Swift 自定义tableview单元格问题

Swift 自定义tableview单元格问题,swift,uitableview,tableviewcell,Swift,Uitableview,Tableviewcell,我在tableView中使用自定义单元格时遇到问题。我正在做的是,我访问我的数据库,对于数据库中的每一行,我将填充一个单元格。问题是,它只为每个单元格反复打印最后一行;然后,我尝试使用过滤器(按ID),但它只打印每个单元格的第一行。 我提前感谢你的帮助。我的代码如下 public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{ var x = Int() do{

我在tableView中使用自定义单元格时遇到问题。我正在做的是,我访问我的数据库,对于数据库中的每一行,我将填充一个单元格。问题是,它只为每个单元格反复打印最后一行;然后,我尝试使用过滤器(按ID),但它只打印每个单元格的第一行。 我提前感谢你的帮助。我的代码如下

public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
var x = Int()
    do{
    let count = try conn.db!.scalar(tblPersona.count)
    x = count
    }
    catch{
    }
    return x
}



public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{

    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! consultaInformacionTableViewCell
    var res = Int64 (1)
    do{

        let query = tblPersona.filter(id == res)
        for custom in try conn.db!.prepare(query){
            print(custom[nombre]!)

            cell.nombreLabel.text = custom[nombre]!
            cell.emailLabel.text = custom[email]!
            res = res + 1
        }
    }
    catch{

    }
    return cell
}

当我打印“custom[nombre]!”时,它会在每次循环完成时打印所有行。

您的筛选条件似乎不正确

tblPersona.filter(id == res)
首先是比较。因此,你实际上是在说:

tblPersona.filter(true)

似乎“true”正在返回每个条目。但是,在不知道您使用的过滤器类型的情况下,我无法提供一个工作示例。

既然您提到了它,程序为什么只打印第一行是有道理的,但我不明白为什么“res”在句子末尾没有递增。从我所看到的,它应该是?您是否仔细检查了代码以验证它没有随着每个循环而递增?我使用了断点,每次新循环启动时,“res”再次等于1。