views:

248

answers:

2

The title pretty much describes it all.

The problem being the handling of the UISegmentedControll callbacks (button presses). If the content type of all of the nested views was the same (i.e. some UITableViewControllers) then I could just switch dataSource'es and reload the tables.

However this is not the case, I have 3 very different views in there that allow further drilldown / interaction based on the NavigationControllers.

So the way I have this set up ATM is that there is a "container" class that I put all of the UINavigationControllers in. They all share the same and one UISegmentedController and I redirect the callbacks to the container view controller. This does not feel too good at all.

Additionally there is a problem when the user taps on the tab bar icon, the navigation controller pops to root which is ... the empty container view.

Here's a picture of what I want to achieve:

alt text

A: 

In one of my apps I have a single table view that is populated from data of three separate NSMutableArrays. I conditionally set the cell contents in cellForRowAtIndexPath, and conditionally get 3 different -counts in numberOfRowsInSection. While this isn't specifically what you are looking for, you don't need to have 3 different data sources as expressed in your initial example.

Your instincts are correct. It does seem overly complex.

How about using one NavigationController and just swapping addSubview/ removeFromSuperview on the NavigationController.view?

David Sowsy
What about the tapping on the TabBar Icon that pops to the root controler (that being an empty view) Is there any sensible remedy for that?I'll try the swapping you mentioned.Cheers
Kaspa
A: 

I've came across a similar feature requirement in a recent iPad application, the solution I used is in the following link - essentially, I implemented a 'managing' view controller, that adds/removes subviews based on the selected index of the segmented control, with correct handling for events.

I solved the navigation controller issue by passing the 'managing' view controller into the subview view controllers as a parameter, and having those controllers call back on the parent to push onto the navigation stack.

What I particularly like about the solution is that it lets me keep the code for each segment's corresponding view separate, and not jumbled within a single overloaded view controller.

Details are here: http://stackoverflow.com/questions/2118358/uisegmentedcontrol-best-practice/2891099#2891099

Good question mate, hope that helps.

crafterm