我能够从表视图中成功删除行,但是在删除一行后,剩余的行将加倍。知道我在做什么错吗?
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
let documentName = documentIds[indexPath.row]
self.documentIds.remove(at: indexPath.row)
deleteItemDocumentAt(index: indexPath.row, name: documentName)
self.collectionItems.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .fade)
}
}
deleteItemDocumentAt从Firebase删除正确的文档。
func deleteItemDocumentAt(index: Int, name: String) {
let itemToDelete = self.collectionItems[index]
let imageUrls = itemToDelete["images"] as? [String]
if imageUrls != nil && (imageUrls?.count)! > 0 {
for url in imageUrls! {
deleteImagesFrom(location: url)
}
}
db.collection("users/\(currentUser.emailAddress!)/collections/\(self.collectionName!)/\(self.collectionName!) Items").document(name).delete() { err in
if let err = err {
print("Error removing document: \(err)")
} else {
print("Document successfully removed!")
self.tableView.reloadData()
}
}
}