ios - How to create menu from UITableView, with unknown number of sub-menus? -


how display multi-level menu uitableview in swift

i'm trying display multi-level menu series of uitableviews, each object may have unknown number of children, may have n number of children, , on.

i'm attempting work closure callback (below), running problems once i'm two-levels deep menu hierarchy.

the relevant code:

tableviewcontroller

override func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) {      var selectedobject:dictionary<string, anyobject>      if (self.haschildren) {        selectedobject  = self.childrenobjects![indexpath.row]     } else {         selectedobject = self.tableviewdata![indexpath.row]     }       self.selectioncallback!(tableview: tableview, indexpath: indexpath, selectedobject: selectedobject, doeshavechildren: self.haschildren) } 

menuviewcontroller

override func viewdidappear(animated: bool) {     super.viewdidappear(true)      let menutableviewcontroller:tableviewbuilder = tableviewbuilder()     menutableviewcontroller.tableviewdata = self.passeddata array<dictionary<string, anyobject>>?      self.navcontroller = uinavigationcontroller(rootviewcontroller: menutableviewcontroller)       self.presentviewcontroller(self.navcontroller!, animated: false) {         print("nav controller presented")         //navcontroller.pushviewcontroller(menutableviewcontroller, animated: false)     }      self.selectedtapcallback = { (tableview, indexpath, selectedobject, doeshavechildrentop) in          let detailmenuviewcontroller:tableviewbuilder = tableviewbuilder()         detailmenuviewcontroller.tableviewdata = selectedobject["children"] as! standardcollectiontype         self.navcontroller!.pushviewcontroller(detailmenuviewcontroller, animated: true)     }        menutableviewcontroller.setselectedcallback(self.selectedtapcallback!)   } 

the data i'm trying represent follows:

    "menu": [                     {                         "title": "jurisdiction",                         "subtitle": "where did ticket?",                         "has_children": true,                         "meta": {                             "top_level_menu": true                         },                          "children": [{                             "title": "new south wales",                             "subtitle": "seeking review office of state revenue (sdro)",                             "has_children": true,                             "meta": {                                 "option_uid": "nsw"                             },                              "children": [{                                     "title": "car registration permit date inccorect",                                     "subtitle": null,                                     "has_children": false,                                     "meta": {                                         "option_uid": "nsw.permit.date.inccorect"                                     }                                 },                                  {                                     "title": "there issue signs",                                     "subtitle": "this due number of reasons",                                     "has_children": true,                                     "children": [{                                             "title": "the signs contradictory",                                             "subtitle": null,                                             "has_children": false,                                             "meta": {                                                 "option_uid": "nsw.bay.signs.contradictory"                                             }                                         },                                          {                                             "title": "the signs unclear",                                             "subtitle": "the signs may have been unclear or ambiguous",                                             "has_children": false,                                             "meta": {                                                 "option_uid": "nsw.bay.signs.unclear"                                             }                                         }                                     ]                                 },                                  {                                     "title": "the offence happened after sold car",                                     "subtitle": "it wasn't me!",                                     "has_children": false,                                     "meta": {                                         "option_uid": "nsw.car.after.sold"                                     }                                 } 

i'm trying handle presenting using closure callback triggered - tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) instantiate menuviewcontroller instance (as in code above), , main navigation controller push it, breaking when trying move third level of menu second level.

any ideas best way handle appreciated!

i developed similar , used library.

hope can you.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -