0

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!

4
  • do you know how many possible sub categories are there? Commented Aug 16, 2016 at 2:20
  • I think there are 3 level sub categories @jo3birdtalk Commented Aug 16, 2016 at 2:25
  • you've just answered your question. just 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. Commented Aug 16, 2016 at 2:29
  • Ah, I see. I think there are any better way to create something like that out there, I am doubting my self with that approach :D Thank you so much, @jo3birdtalk Commented Aug 16, 2016 at 2:32

1 Answer 1

1

Create 3 UITableViewControlle‌​rs (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)
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.