how can I start with one view then switch to another

Discussion in 'iOS Programming' started by munkees, Jul 7, 2009.

  1. munkees macrumors 65816

    munkees

    Joined:
    Sep 3, 2005
    Location:
    Pacific Northwest
    #1
    I am making my first app, I have a tab bar to switch my 5 basic views, but at startup I want a non tab view to be displayed for the first time the app is run, then after that the tab bar.

    Any Idea how I can make that happen?
     
  2. johnmcglone macrumors newbie

    Joined:
    Jun 30, 2009
    #2
    An easy way to do this is to make an IBOutlet for each of the 2 different views you want switch from, and add them to your main view in Interface Builder.

    Once the code and Interface are linked up, create a button that calls an action that will switch the views. Pseudo code:

    ***MyAppViewController.h***
    ..
    IBOutlet UIView *view1;
    IBOutlet UIView *view2;
    UIView *currentView;
    ..
    ***MyAppViewController.m***
    ..//in view did load, or init function
    [self.view addSubView:view1];
    [self.view addSubView:view2];

    currentView = view1;
    [currentView bringToFront];
    ..
    ..
    -(IBAction)switchView
    {
    if(currentView == view1)
    currentView = view2;
    else
    currentView = view1;

    [currentView bringToFront];
    }
    ..


    This might not be the neatest way to do it, but it works. Some would decide to load and unload views as needed, rather than loading them ALL then rearranging the order. Ultimately, it's up to you. With only two views, and assuming there isn't much data on them, this is fine.
     
  3. munkees thread starter macrumors 65816

    munkees

    Joined:
    Sep 3, 2005
    Location:
    Pacific Northwest
    #3
    thank you, I was nearly there, but you helped me out a lot. now it is working.
     

Share This Page