新的FUITableViewDataSource-如何使用?斯威夫特3 [英] New FUITableViewDataSource - how to use? Swift 3
问题描述
仅更新到了较新的FirebaseUI Pod-发生了一些变化,但是最大的变化之一是FUI Table View的工作方式.我在较旧的版本上运行良好,但是在下面遇到了这一问题-缺少文档/示例.
Just updated to the newer FirebaseUI Pod - a few things have changed but one of the big ones is the way that the FUI Table View works. I had it working well on an older version but 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#>)
我不知道从哪里调用indexpath.我需要单独创建一个NSIndexPath
来传递它吗?我也不太了解它应该放在哪里-以前,它是FirebaseTableViewDataSource
,我将其设置在viewDidLoad
中,它将直接从中创建单元格等.现在看来,它似乎需要存在于我的cellForRowAtIndexPath
中.有人对此有任何建议吗?
I don't understand where the indexpath is being called from. Do I need to make a seperate NSIndexPath
to pass into that? I also don't really understand where this is supposed to live - previously, with it was FirebaseTableViewDataSource
, I would set it in my viewDidLoad
, and it would create the cells etc straight from that. It almost now looks as though it needs to live in my cellForRowAtIndexPath
. Does anyone have any advice on this?
推荐答案
测试使用tableView:bind:方法(好像它们做了UITableView类扩展),并且我能够使其正常工作.
The test for this latest version uses a tableView:bind: method (seems like a UITableView class extension they made) and I was able to get it to work.
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
})
}
还要确保您正在观察更改查询,否则tableView不会被填充
Also make sure you are observing your query for changes or else the tableView won't get populated
self.query?.observe(.value, with: { snapshot in
})
这篇关于新的FUITableViewDataSource-如何使用?斯威夫特3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!