PDA

View Full Version : Two Root UIViews with Segmented Control?




kwjohns
Apr 10, 2009, 10:19 PM
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.

http://img.photobucket.com/albums/v57/kaje103/example.png

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.



B U G E Y E
Apr 11, 2009, 02:53 AM
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...

kwjohns
Apr 11, 2009, 09:26 AM
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.

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