删除后重新加载collectionView

时间:2017-04-13 01:44:49

标签: ios firebase swift3 firebase-realtime-database

我正在使用firebase。我的代码工作但我的问题是当我按下接受按钮时,我希望从collectionView中删除该索引,我希望该表立即重新加载。我不能使用幻灯片删除,因为我需要它用于其他功能。

enter image description here

这是在我的单元类中,这就是为什么我没有使用self.来调用collectionView。此函数由addTarget()方法调用。我想可能会将indexPath作为参数传递,但我不知道如何将indexPath.item作为参数传递,以及如何在addTarget()方法中传递参数。

func handleAccept(_ sender: UIButton) {
        print("button pressed")
        guard let artId = art?.artId else {return}
        let approvedRef = 
    FIRDatabase.database().reference().child("approved_art")
        approvedRef.updateChildValues([artId: 1])
        let pendingRef = 
    FIRDatabase.database().reference().child("pending_art").child("\(artId)")
        pendingRef.removeValue { (error, ref) in
            if error != nil {
                return
            }
            let layout = UICollectionViewFlowLayout()
            let pendingArtCollectionViewController = 
    PendingArtsCollectionViewController(collectionViewLayout: layout)
            DispatchQueue.main.async {
                pendingArtCollectionViewController.collectionView?.reloadData()
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

您不需要将indexpath作为参数传递,您可以使用以下代码获取tableView in button action的索引路径:

func handleAccept(_ sender: UIButton) {
    let center = sender.center
            let rootViewPoint = sender.superview!!.convert(center!, to: self.myTableView)
            let currentIndexpath = myTableView.indexPathForRow(at: rootViewPoint)
    }
相关问题