Two Root UIViews with Segmented Control?

Discussion in 'iOS Programming' started by kwjohns, Apr 10, 2009.

  1. kwjohns macrumors 6502a


    Jul 4, 2007
    I have a root view that has some icons on it that when pressed will take you into a navigation controller. However, I need to add more icons than what will fit on the view, therefore I would like to separate some of the icons within different segments with a segmented control. So I'm wanting to load a different view (xib) when a different segment is selected. I'm not having any luck finding any examples that explain how to push another root view, though. All I can find is how to push a view deeper into a navigation controller.

    Hope this makes sense.

    Edit: Here's an example of what I mean.


    I have the segmented control code setup, I just don't know what to put within:

    UISegmentedControl* segCtl = sender;
    	if( [segCtl selectedSegmentIndex] == 0 ){
    	if( [segCtl selectedSegmentIndex] == 1 ) {
    to load the different xib.
  2. B U G E Y E macrumors newbie

    Apr 2, 2009
    Portland, OR
    If all you're going to need are the two views, you could just create them both, and use the segmented control to toggle the "hidden" property on each. Actually, just toggling the foremost one might be enough.

    If you want to use a navigation controller, you can use one view as the root view, and the other as a pushed view. I did this in one of my apps. Just pass NO for the "animated" parameter and the view will just appear. Something like this:

    if ( [segCtl selectedSegmentIndex] == 0 ) {
        [navController popToRootViewControllerAnimated:NO];
    } else if ( [segCtl selectedSegmentIndex] == 1 ) {
        [navController pushViewController:someViewController animated:NO];
    Hope that helps...
  3. kwjohns thread starter macrumors 6502a


    Jul 4, 2007
    Ah that will work! For some reason I was thinking different view = different xib file. Not the case! Thanks!

Share This Page