【问题标题】:Reloading the collectionView after delete删除后重新加载collectionView
【发布时间】:2017-04-13 01:44:49
【问题描述】:

我正在使用火力基地。我的代码有效,但我的问题是当我按下接受按钮时,我希望从 collectionView 中删除该索引,并且我希望表在之后立即重新加载。我无法使用幻灯片删除,因为我需要它来执行其他功能。

这是在我的单元格中,这就是为什么我没有使用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()
            }
        }
    }

【问题讨论】:

  • 只需要tableview对应行的indexpath吗?

标签: ios firebase swift3 firebase-realtime-database


【解决方案1】:

您不需要将 indexpath 作为参数传递,您可以使用以下代码在按钮操作中获取 tableView 的 indexpath:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-20
    • 1970-01-01
    • 1970-01-01
    • 2017-06-30
    相关资源
    最近更新 更多