0

I have seen some questions asking about switching view controllers using a segmented control, but none of the suggestions seem to fit my needs.

I have a tab bar application with 3 tabs. The first tab is a navigation controller with a tableview as its root. When one of the rows is selected, I push a view controller X onto the navigation stack.

In controller X, I wish to use the segmented control to be placed in the bottom toolbar (as opposed to the titleview in many samples). Controller A would be shown inside controller X if the first segment is selected, controller B would be shown if the second segment is selected, whilst keeping the toolbar to be the same for A and B. What's the best approach to this problem?

Thanks, Joe

2
  • I created a test project to demonstrate what you're looking for. At this time, it works but I believe that it's a hack and you should consider reading the View Controller Programming Guide to better understand content and container view controllers and how they work. What you're looking to do is use a content view controller as a container for another view controller's view. "A" is a content view controller that you want to contain "X". Let me know if you want the code but I feel that posting it would not be beneficial in the event of future searches. Apr 4, 2012 at 4:56
  • @brian could you post the code sample please? So I guess the best solution is to make A and B to be just views, and use X to load the views as the selected segment changes? It does lead to more memory usage though I suspect, since both A and B both need to be loaded even if I'm just viewing A. I thought about making X as a NavigationController to handle switching between A and B as controllers (and hide the nav bar), but X is already a pushed controller, so that route doesn't seem possible either (can't push a navcontroller into another navcontroller)
    – Joe Tam
    Apr 4, 2012 at 18:09

0

Your Answer

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