我正在使用swift和firebase开发iOS应用程序。我在UITableView的Prototype Cell中有4个标签,我想用firebase中的数据填充它们。谢谢你帮助我;)
import UIKit
import Firebase
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var date: NSDate!
let ref = Firebase(url:"https://HIDDEN.firebaseio.com")
let childRef = Firebase(url:"https://HIDDEN.firebaseio.com/User")
let childChildRef = Firebase(url:"https://HIDDEN.firebaseio.com/User/List")
@IBOutlet var tableList: UITableView!
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)
-> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
as! CustomCell
childChildRef.observeEventType(.Value, withBlock: {
snapshot in
cell.name.text = String(snapshot.value.objectForKey("Name"))![indexPath.row]
cell.age.text = String(snapshot.value.objectForKey("Age"))![indexPath.row]
cell.stat.text = String(snapshot.value.objectForKey("Stat"))![indexPath.row]
cell.notes.text = String(snapshot.value.objectForKey("Notes"))![indexPath.row]
self.tableList.reloadData()
})
return cell
}
}