0

i am coding a project in which some products with their respective categories and subcategories are read from an xml file and then must be displayed in a UITableView.

Problem is, that there is no fixed depth of levels (the xml tag reads like this: Category > subcategory > subsubcategory > ... > etc) so i can't have a fixed set of views and thus to use a UINavigationController.

So at the moment - and it's working pefectly - i read the data from some NSMutableArrays i have loaded from the xml file and i am showing them in a UITableView. Working as intended. The objects even have links to eachother and so the new data set is a child of the element last pressed on the UITableView.

But, obviously, i need a back button, and this is where i got stuck, i've done it with UINavigationController before, but i can't seem to find a way to

a) add a back button to the navigation bar (I added a UINavigationBar via the IntefaceBuilder and linked it to the IBOutlet)

b) associate some code to call the previous data set when the button is pressed.

Any help?

2 Answers 2

0

You should still follow the usual navigation controller design pattern. If you have multiple levels of categories, call the same view controller recursively.

I once did such an implementation (also on the basis of an xml file) where in didSelectRowAtIndexPath: I would check if the object selected has any more "children" - in which case I would push another equivalent view controller on top of the navigation stack; if not, I would present the detail view controller.

9
  • thing is, that with my current design i am only using one view controller, the one that contains the table (and the nav-bar) and i am just reloading the table's data each time the user taps an item.
    – magtak
    Oct 12, 2011 at 11:10
  • I see - I still think going with multiple instances of UITableViewController is the better approach. (You would not have to write a new controller subclass.) In this way, you also do not have to implement your own animations etc.
    – Mundi
    Oct 12, 2011 at 13:52
  • since i am kinda new to ObjC and though i understand the notion, i am having a hard time figuring out how to do it, mind tossing me some dummy code on how to work around on multiple instances of UITableViewController? I mean, where in the class (which is the tableView's delegate and datasource) should i be creating them and how? Thanks in advance.
    – magtak
    Oct 13, 2011 at 7:24
  • I ultimately added a UINavigationController for the passing from the categories to the product view itself, but still all the categories are handled from one UINavigationController and i would like to change that to comply to your (more logical) model
    – magtak
    Oct 13, 2011 at 10:04
  • Well, you made it work. How are you handling the animations from one level to the next?
    – Mundi
    Oct 13, 2011 at 19:40
0

If you want to achieve this you have to implement a stack structure, with it's functions to push and pop. Just the same way as UINavigationController works. If your solution is not a fully customized one I would simply use UINavigationController pushing UITableViewControllers and have it handle the stack for me, as opposed to re-inventing the wheel.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.