删除行后剩余的行加倍

时间:2018-11-16 13:26:25

标签: ios swift uitableview

我能够从表视图中成功删除行,但是在删除一行后,剩余的行将加倍。知道我在做什么错吗?

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()
            }
        }
    }

此屏幕截图在删除之前: enter image description here

此屏幕截图位于删除之后。剩余行会出现两次。 enter image description here

0 个答案:

没有答案