-1
我在自定义单元格在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]!”时,它会在每次完成一个循环时打印所有行。
现在你提到它,有道理为什么程序只打印第一行,但我不明白为什么“res”不会在句子末尾增加 –
从我所看到的,它应该是?你是否已经通过代码来验证每个循环都不会递增? – Software2
我使用断点,每次新循环开始时,“res”等于1。 –