2017-09-05 4 views
0

私のアプリには簡単な通知ページがあり、アプリ内で要求する友人を設定しています。友人のリクエストやメッセージの通知が追加されると、レシーバのメッセージページに移動します。ユーザーが友だちの辞退要求を選択すると、アラートビューは表示されなくなりますが、表ビューは項目の倍数でリロードされます。私は、クリックを受け入れるか拒否した後にリロードする関数はありません。私はすべてを試して、私はいくつかの助けを得ることができるといいです。ここにいくつかのコードと何が起こっているの写真です。通知を取得するための私のpull()関数はviewdidloadで呼び出され、viewwillappear関数のviewdidappearは呼び出されないことに注意してください。プル機能は、それを通知配列に入れる基本的なfirebaseループフェッチです。firebaseの値を削除すると、tableviewが2倍の要素で再読み込みされます

現在のコード:ただ受け入れる/辞退 After clicking accept

答えて

0

をクリックした後トミーのメッセージ First

をクリックし、それは友達のリクエストであるかどうかを確認、キャンセルセグエメッセージと現在のアラートビュー

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 

私は受け入れと拒否の両方の機能の後にこれを追加しました:

  • self.notifications.removeAll()

  • self.tableViewNotifications.reloadData()

関連する問題