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: structure

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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -