New FUITableViewDataSource - how to use? Swift 3

Just upgraded to the new FirebaseUI Pod - a few things have changed, but one of the big ones is how the FUI table view works. I had this work well on an older version, but I am struggling with this below - and the lack of documentation / examples.

self.dataSource = FUITableViewDataSource(query: <#T##FIRDatabaseQuery#>, view: <#T##UITableView#>, populateCell: <#T##(UITableView, IndexPath, FIRDataSnapshot) -> UITableViewCell#>) 

I do not understand where indexpath is being called from. Do I need to make a separate NSIndexPath to get to this? I also don’t understand where it should live - earlier, with this there was a FirebaseTableViewDataSource , I would set it in my viewDidLoad , and it would create cells, etc. Straight from that. Now almost everything looks as if it should live in my cellForRowAtIndexPath . Does anyone have any advice on this?

+5
source share
1 answer

test for this latest version uses the tableView: bind: method (it looks like it's an extension of the UITableView class that they did), and I was able to get it working.

 override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) let firebaseRef = FIRDatabase.database().reference().child(/*insert path for list here*/) let query = firebaseRef.queryOrderedByKey() /*or a more sophisticated query of your choice*/ let dataSource = self.tableView.bind(to: query, populateCell: { (tableView: UITableView, indexPath: IndexPath, snapshot: FIRDataSnapshot) -> UITableViewCell in let cell = tableView.dequeueReusableCell(withIdentifier: "cellIdentifier", for: indexPath) let value = snapshot.value as! NSDictionary let someProp = value["someProp"] as? String ?? "" cell.textLabel?.text = someProp return cell }) } 

Also make sure that you are watching the change request, otherwise the tableView will not be populated.

 self.query?.observe(.value, with: { snapshot in }) 
+5
source

Source: https://habr.com/ru/post/1260478/


All Articles