how to correctly switch between views

Discussion in 'iPhone/iPad Programming' started by printf, Jul 3, 2010.

  1. macrumors regular

    Joined:
    Aug 27, 2008
    #1
    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!
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Use a navigation controller and push/pop between the view. You can hide the navigation bar if you want.
     
  3. thread starter macrumors regular

    Joined:
    Aug 27, 2008
    #3
    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.
     
  4. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    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.
     
  5. thread starter macrumors regular

    Joined:
    Aug 27, 2008
    #5
    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?
     
  6. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    I would recommend instead, based on your needs, just presenting the splash screen modally and then dismissing it upon touch.
     

Share This Page