Reputation: 1246
I have a JSON tree that represent address. Something like this,
- Address Tree
- Address Tree Deeper
- Address Tree Deeper
- Address Tree Deeper
- Address Tree More Deeper
- Address Tree More Deeper
- Address Tree More Deeper
- Address Tree More Deeper
- Address Tree Deepest
- Address Tree Deepest
- Address Tree Deepest
- Address Tree Deepest
- Address Tree
- Address Tree Deeper
- Address Tree Deeper
- Address Tree Deeper
- Address Tree More Deeper
- Address Tree More Deeper
- Address Tree More Deeper
- Address Tree More Deeper
- Address Tree Deepest
- Address Tree Deepest
- Address Tree Deepest
- Address Tree Deepest
I want to display that tree using table and user could select its child, but I don't know how to represent that. I mean, should we create multiple ViewController
(and ofcourse its scene in storyboard) then we push every we go deeper into address child? Or maybe I could create UITableView
programmatically?
Or there are any approach that I can use for that case? I think about reusing viewcontroller but I don't have any clue.
Any help would be appreciated. Thank you so much!
Upvotes: 0
Views: 155
Reputation: 616
Create 3 UITableViewControllers (since it is the maximum) inside your IB, and push the view controllers accordingly if that dictionary has sub categories in it.
An example how you should do it:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if(yourDictionary[indexPath.row].yourVariable != nil){
let nextViewController = self.storyboard?.instantiateViewControllerWithIdentifier("nextViewController") as! ScoutPage
self.navigationController?.pushViewController(nextViewController, animated: true)
}
}
Upvotes: 1