ios - TableViewCell Data from Firebase Database -
so want holes database , put them in tableview don't know how. cant figure out how cells title number of hole.
here database:
here viewcontroller:
import uikit import firebase class holesviewcontroller: uitableviewcontroller { //firebaserefrences var ref = firdatabasereference.init() var holes: [firdatasnapshot]! = [] override func viewdidload() { //viewdidload //refrences firebase ref = firdatabase.database().reference() let coursesref = ref.child("courses") //snapshot coursesref.observeeventtype(.childadded, withblock: { snapshpt in self.holes.append(snapshpt) self.tableview.reloaddata() }) } override func viewdidappear(animated: bool) { //viewdidappear } override func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { return self.holes.count } override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let cell: uitableviewcell! = self.tableview.dequeuereusablecellwithidentifier("holecell") let holessnap = self.holes[indexpath.row] /* ?????? */ return cell } override func tableview(tableview: uitableview, caneditrowatindexpath indexpath: nsindexpath) -> bool { return true } }
as can see holes
array array of course snapshots.
if want array holes of courses need work following
self.holes = snapshpt.childsnapshotforpath("holes").children.allobjects [firdatasnapshot]
if want holes especific course should retrieving data
ref.child("courses").child(courseid).child("holes").observeeventtype(.childadded withblock: { snapshot in self.holes.append(snapshot) }
one time have holes snapshots (one snapshot each hole) in holes[indexpath.row]
, have set cell textlabel
snapshot value.
cell.textlabel = holes[indexpath.row].value as! string
Comments
Post a Comment