Navigation-like behaviour without UINavigationController
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 开发者_Python百科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?
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.
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.
精彩评论