View Full Version : how to correctly switch between views

Jul 4, 2010, 01:55 AM
i have a uiview and a uiwebview. at the moment they have no relationship with one another because i'm stuck at figuring out the 'correct' way to set them up. it really makes no difference to me, but i'd like to know which way is best.

on one hand, i could make the uiwebview a subview of my uiview. that would work for my purposes. however, it just seems weird that i'd be setting this up within my custom uiview class - i mean, isn't this the job of a viewcontroller?

on the other hand, i could treat both views as equals and let the view controller switch them out perhaps? but my custom uiview responds to events (such as touchesEnded) and only it knows when it's time is up and it's to be replaced by the uiwebview. the viewcontroller has no knowledge of this and therefore cannot know when to switch between the two.

any insight on the best approach here? thanks!

Jul 4, 2010, 04:37 AM
Use a navigation controller and push/pop between the view. You can hide the navigation bar if you want.

Jul 5, 2010, 05:43 PM
ah, i overlooked the navigation controller because i didn't know the nav bar could be removed.

still curious though, is there a way for one view to inform the nav controller that it's ready to be switched out with the other view? like from a touchesEnded event that's captured in that view?

btw, i'm not using IB.

Jul 5, 2010, 05:48 PM
I'm not clear by what you mean by "switched out". Any view in a navigation controller can either push another view controller into the navigation stack or pop itself off the navigation stack.

Jul 5, 2010, 08:35 PM
right, and that's the part i'm confused with. every ui nav controller example i've seen on the web uses buttons hooked into ibactions in the app delegate to push/pop views.

my requirement is a little different. i have a 'splash screen' view that displays fade-in animation and should pop the splash view and push the main application view onto the nav stack when the animation is complete OR a user 'touches' the view anywhere. i'm still an mvc novice, so i'm not sure how to get the splash screen view to tell the navigation controller to push the main view. does that make sense?

Jul 5, 2010, 10:48 PM
I would recommend instead, based on your needs, just presenting the splash screen modally and then dismissing it upon touch.