Reputation: 9869
I am trying to drilldown and drillup throughout a hierarchical menu using a series of UITableViewControllers. Since each UITableViewController is exactly the same except for its particular datasource, I am only using one UITableViewController class. For example, level 1 is an array of last names, level 2 is an array of first names, level 3 is an array of birthdates. Rather than have 3 UITableViewControllers (one for the last names, one for the first names, and one for the birthdates), I have only one UITableViewController and just alloc/init a brand new UITableViewController, but initialize it with the datasource arrays with each successive drilldown (i.e., didSelectRowAtIndexPath). If I needed to drill down to a fourth level, I could just switch out the arrays and we're all good. It scales better that way.
I can go "forwards" and drill down correctly. It's flawless. But when I go backwards, i.e., click the "back" button of the UINavigationController, I am getting the "parent's" data indeed, or so it appears. But when I actually click on a cell to go forwards again, it looks like my datasources are actually not being switched out under the hood. It appears to be cached correctly, but when I go to click on the data, actually level 2's data source is not actually backed by level 2's data anymore. It's actually got level 3's data, which is the UITableViewController that I just popped off the stack.
Do I need to override the UINavigationController's "back button" and then update my datasources when popping off the stack? I am not sure what I am missing here. My UITableViewCode is almost 1000 lines long, and this is the generic problem that I'm facing.
Table1 Table2 Table3
smith --> Joe --> 1/1/1980
hit "back"
Table2
Joe is displayed (correct)
tap "Joe" again --> 6/23/1976 (indicating that this is someone else's birthdate, so the datasources have gotten mixed up.)
So going forwards is correct, but going backwards seems to mix up datasources.
Upvotes: 0
Views: 163
Reputation: 12224
Consider taking a look at how this project does it. It is doing the exact thing you describe instead it creates table hierarchies from a plist. Navigating back and forward in the sample app works fine, and you can alter the plist to include more levels.
Upvotes: 1