这是错误...
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete row 4 from section 0 which only contains 0 rows before the update'
发生此错误的代码如下。
cell.imageView?.sd_setImage(with: fileUrl as URL?, placeholderImage: placeholderImage,
options: [],
progress: nil,
completed: { (image, error, cacheType, imageURL) in
guard let image = image else { return }
//print("Image arrived!")
cell.imageView?.image = self.resizeImage(image: image, newWidth: 50)
let indexPath = NSIndexPath(row: self.usersArray.count-1, section: 0)
self.tableview.reloadRows(at: [indexPath as IndexPath], with: .none)
cell.isHidden = false
})
当我删除这两行时,不会发生错误
let indexPath = NSIndexPath(row: self.usersArray.count-1, section: 0)
self.tableview.reloadRows(at: [indexPath as IndexPath], with: .none)
但是我需要在单元格中加载图像之后重新加载TableView。
如何解决?,希望您能为我提供帮助,非常感谢。
答案 0 :(得分:1)
我认为这是ViewController中的一条鳕鱼。 也许可以用
cell.imageView?.sd_setImage(with: fileUrl as URL?, placeholderImage: placeholderImage,
options: [],
progress: nil,
completed: { [weak self] (image, error, cacheType, imageURL) in
guard let 'self' = self else { return }
guard let image = image else { return }
//print("Image arrived!")
cell.imageView?.image = self.resizeImage(image: image, newWidth: 50)
DispatchQueue.main.async {
let indexPath = IndexPath(row: self.usersArray.count-1, section: 0)
self.tableview.reloadRows(at: [indexPath], with: .none)
}
cell.isHidden = false
})
答案 1 :(得分:-1)
尝试使用开始更新开始更新特定单元格,并使用结束更新结束特定单元格,希望这可以解决您的问题:
__tableView.beginUpdates()
let rowToReload = IndexPath(row: usersArray.count - 1, section: 0)
__tableView.reloadRows(at: [rowsToReload], with: .none)
__tableView.endUpdates()