我正在使用FirebaseUI-IOS和FirebaseTableViewDataSource綁定到我的UITableView。對於我的實現,UITableView應該顯示邀請處於「掛起」狀態以連接用戶,類似於LinkedIn。存儲在Firebase中的邀請數據的狀態鍵可以是「待處理」,「已接受」或「已拒絕」。我很努力的讓UITableView在用戶接受/拒絕邀請後更新並且只顯示'等待'行。目前發生的事情是UITableView單元格被更新(名稱標籤更改爲默認文本),但單元格仍然顯示。看起來,UITableView綁定到用戶「收到」節點下的所有行,而不是在狀態!='pending'時進行響應。firebaseui-ios FirebaseTableViewDataSource與UITableView同步
Firebase 'Invitation' data structure
我使用viewDidLoad中下面的代碼()來初始化FirebaseTableViewDataSource和填充細胞:
//Initialise a Firebase reference to the authorised user's 'received' invitations data
self.ref = Firebase(url: "\(kFBInvitationsUsersRef)/\(authData.uid)/received")
//Query the location for invitations where the status is pending only
self.ref.queryOrderedByChild("status").queryStartingAtValue(InvitationStatus.pending.rawValue).queryEndingAtValue(InvitationStatus.pending.rawValue).observeEventType(.ChildChanged , withBlock: {(snapshot) in
})
//Assign the tableview datasource to a new FirebaseTableViewDataSource instance using the Firebase ref created above
self.dataSource = FirebaseTableViewDataSource(query: self.ref, modelClass:nil, prototypeReuseIdentifier: "invitationCell", view: self.tableView)
//Call the populateCellWithBlock method and configure the cell
self.dataSource.populateCellWithBlock { (cell: UITableViewCell, obj: NSObject) -> Void in
let cell = cell as! InvitationTableViewCell
let snap = obj as! FDataSnapshot
if let status = snap.value["status"] as? String where status == InvitationStatus.pending.rawValue {
let userRef = Firebase(url: "\(kFBUsersPublicRef)/\(snap.key)")
userRef.observeSingleEventOfType(.Value, withBlock: {snapshot in
let user = User(key: snapshot.key, displayName: snapshot.value["displayName"] as! String, givenName: snapshot.value["givenName"] as! String, familyName: snapshot.value["familyName"] as! String)
cell.user = user
cell.delegate = self
})
}
}
self.tableView.dataSource = self.dataSource
self.tableView.delegate = self
}
能
人
我在火力地堡數據結構如下幫助診斷我在這裏做錯了什麼?我的方法是否正確?
感謝您提供任何幫助!
這並不完全清楚你想要做什麼。你是否想要查詢所有待處理的數據並根據該查詢填充tableView(Firebase處理過濾)?或者你想填充一個tableView與掛起,結果在代碼中被過濾?你想觀看持續的變化嗎?如果您還沒有這樣做,請查看[Build Better Mobile Apps](https://www.firebase.com/blog/2015-08-27-firebaseui-makes-mobile-easy.html)。記下iOS快速入門代碼並在此基礎上進行構建。如果你簡化你的代碼,答案可能會出現。 – Jay
@Jay,感謝您的意見,抱歉,如果要求不明確。我試圖讓tableView顯示狀態爲pending的所有行。當用戶通過點擊單元格中的接受或拒絕按鈕更新狀態時,該行從tableView中消失。我想通過觀察對狀態鍵的更改來實現此目的。現有的代碼基於您提供的鏈接中描述的結構。 – AlexM
問題:爲什麼queryOrderedByChild有空塊? - 該查詢返回時調用該塊。此外,queryEqualToValue(「掛起」)可能更清晰,如果這就是你正在尋找的..如果意圖是查詢掛起,那麼爲什麼還要檢查代碼中的「掛起」?這個陳述是否正確:當用戶點擊接受或拒絕時,這個改變被寫出到Firebase中,然後重新加載tableView? – Jay