Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

munkees

macrumors 65816
Original poster
Sep 3, 2005
1,027
1
Pacific Northwest
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?
 

johnmcglone

macrumors newbie
Jun 30, 2009
5
0
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.
 

munkees

macrumors 65816
Original poster
Sep 3, 2005
1,027
1
Pacific Northwest
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.

thank you, I was nearly there, but you helped me out a lot. now it is working.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.