ios - Read Data from Firebase and put it in Cells in TableView -


so want amount of holes uialert , put them in database , receive them in other view controller fill example 18 cells each have title 1 - 18, don't know how example 18 cells , cell 1 have title 1 , cell 2 have title 2 , on.

here's database:

structure

here's want add holes tableview:

class holesviewcontroller: uitableviewcontroller {      //todo add cells firebase inside courses.child      //g/l input data in next viewcontroller       //firebaserefrences     var ref = firdatabasereference.init()      var holes: [firdatasnapshot]! = []      override func viewdidload() {          //viewdidload            //refrences firebase          ref = firdatabase.database().reference()         let coursesref = ref.child("courses")         var holes: [firdatasnapshot]! = []           print()            //snapshot          coursesref.observeeventtype(.childadded, withblock: { snapshpt in              //self.courses.append(snapshpt)             //self.tableview.reloaddata()             //print(snapshpt.childsnapshotforpath("holes"))              self.holes.append(snapshpt.childsnapshotforpath("holes"))             print(self.holes)              //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]          let holes = holessnap.value          /*           ??????          */          return cell     }      override func tableview(tableview: uitableview, caneditrowatindexpath indexpath: nsindexpath) -> bool {          return true     }   } 

here's data holes from:

@ibaction func addbuttondidtouch(sender: anyobject) {           // alert view input          let alert = uialertcontroller(title: "course item",message: "add course",preferredstyle: .alert)          let saveaction = uialertaction(title: "save", style: .default) { (action: uialertaction) -> void in              //get date string             let date = nsdate()             print(date)              let dateformatter = nsdateformatter()             dateformatter.dateformat = "dd-mm-yyyy 'at' hh:mm"             let datestring = dateformatter.stringfromdate(date)             print(datestring)             //             let coursefield = alert.textfields![0]             let holesfield = alert.textfields![1]                let courses = self.ref.child("courses").childbyautoid()              let course = ["addeddate": datestring anyobject,                           "coursename": coursefield.text as! anyobject,                           "amountofholes": holesfield.text as! anyobject]              courses.setvalue(course)              //set holes inside courses              let holes = courses.child("holes")             //let holeschild = holes.child("")             let eightteenholes = ["1": "1",                                  "2": "2",                                  "3": "3",                                  "4": "4",                                  "5": "5",                                  "6": "6",                                  "7": "7",                                  "8": "8",                                 "9": "9",                                 "10": "10",                                 "11": "11",                                 "12": "12",                                 "13": "13",                                 "14": "14",                                 "15": "15",                                 "16": "16",                                 "17": "17",                                 "18": "18"]              let nineholes = ["1": "1",                                  "2": "2",                                  "3": "3",                                  "4": "4",                                  "5": "5",                                  "6": "6",                                  "7": "7",                                  "8": "8",                                  "9": "9"]              let sixholes = ["1": "1",                             "2": "2",                             "3": "3",                             "4": "4",                             "5": "5",                             "6": "6"]              if holesfield.text == "18"{                  holes.setvalue(eightteenholes)              } else if self.amonuofholes == "9"{                  holes.setvalue(nineholes)              } else if self.amonuofholes == "6"{                  holes.setvalue(sixholes)              }            } 


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 -

android - CoordinatorLayout, FAB and container layout conflict -