2017-09-05 48 views
0

我有一個簡單的通知頁面在我的應用程序,我已經設置了朋友請求內的應用程序,並且當一個朋友請求或消息通知時,它被添加到接收者消息頁面。當用戶選擇拒絕好友請求時,警報視圖關閉,但是然後tableview用雙重項目重新加載,對於接受相同。點擊接受或拒絕後,我沒有要求重新加載它的功能。我已經嘗試了一切,希望能得到一些幫助。這是一些正在發生的事情的代碼和照片。請注意,我用於獲取通知的pull()函數在viewdidload中被調用,並且沒有viewdid在視圖中出現的函數調用。 pull函數是一個基本的firebase循環獲取,將其放入通知數組中。firebase刪除值導致tableview重新加載元素的兩倍

當前代碼:檢查它是否是一個朋友的要求,取消賽格瑞消息和存在提醒視圖

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 

只需點擊湯米的消息 First

點擊接受/拒絕 After clicking accept

回答

0

後我在接受和拒絕功能之後添加了這個:

  • self.notifications.removeAll()

  • self.tableViewNotifications.reloadData()