【问题标题】:firebase remove value causes tableview to reload with double the elementsfirebase 删除值导致 tableview 重新加载元素的两倍
【发布时间】:2017-09-05 03:28:43
【问题描述】:

我的应用上有一个简单的通知页面,我在应用中设置了好友请求,当收到好友请求或消息的通知时,它会添加到接收者消息页面。当用户选择拒绝好友请求时,警报视图会关闭,但随后表格视图会重新加载双倍的项目,对于接受也是如此。单击接受或拒绝后,我没有调用函数来重新加载它。我已经尝试了一切,希望能得到一些帮助。这是正在发生的事情的一些代码和照片。请注意,我在 viewdidload 中调用了用于获取通知的 pull() 函数,并且没有调用 viewwillappear 函数的 viewdidappear。 pull 函数是一个基本的 firebase 循环获取,将其放入通知数组。

当前代码:检查是否是好友请求,取消segue消息并显示警报视图

    override func shouldPerformSegue(withIdentifier identifier: String,   sender: Any?) -> Bool {
    if identifier == "segueNotify" {
        let index = tableViewNotifications.indexPathForSelectedRow!
        if let friendReques = notifications[index.row].friendRequest {
   let decline = UIAlertAction(title: "Decline", style: .default, handler: { (action : UIAlertAction!) -> Void in
                if let myuid = self.uid {
                    if let key = self.notifications[index.row].key {
                        let ref = FIRDatabase.database().reference()                       

   ref.child("users").child(myuid).child("Notifications").child(key).removeValue()

                    }
                }
   // this does not work, does the same thing :
   // self.notifications.removeAll()
             //self.tableViewNotifications.reloadData()
               //self.pull()
            })

            let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
            alert.addAction(cancel)
            alert.addAction(accept)
            alert.addAction(decline)
            self.present(alert, animated: true, completion: nil)
            return false
        }
    }
    return true

只需点击汤米的消息

点击接受/拒绝后

【问题讨论】:

    标签: ios swift uitableview firebase


    【解决方案1】:

    我在接受和拒绝功能之后添加了这个:

    • self.notifications.removeAll()

    • self.tableViewNotifications.reloadData()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-22
      • 1970-01-01
      相关资源
      最近更新 更多