我试图说服我的应用程序遍历手机本地存储的SQLite数据库,然后用结果填充单元格。查询是通过使用SQLite.swift完成的
我想过使用indexPath.row和SQL的LIMIT选项遍历单元格,但我不知道我的方法是否正确。
到目前为止我的代码如下:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCells") as! SettingTableViewCell
do {
let query = fatherTable.limit(indexPath.row, offset: indexPath.row)
for father in try self.localDatabase.prepare(query) {
cell.label1.text = father[self.fatherName]
cell.label2.text = father[self.fatherLastName]
cell.label3.text = father[self.fatherAge]
}
}
catch {
print(error)
}
return cell
}
发布于 2018-12-20 08:19:27
您的方法不正确,您需要获取viewDidLoad
中的所有项,然后重新装入表(如果您将异步执行此操作),在cellForRowAt
中获取对于性能而言是错误的,而且它将为最后一项设置单元格,因为每个单元格都调用cellForRowAt
https://stackoverflow.com/questions/53860897
复制相似问题