In my app, I have 5 tabs for navigation.
However I would like my middle tab (tab 3) to be the one that is first displayed when the app is first loaded.
Is there a way to do this?
In my app, I have 5 tabs for navigation.
However I would like my middle tab (tab 3) to be the one that is first displayed when the app is first loaded.
Is there a way to do this?
first loaded means first time ever? or for every new launch? this code is for first time ever, but without NSUserDefault
can be used to every new launch
appDelegate.h
@property (strong, nonatomic) UIWindow *window;
appDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];
UITabBarItem *tabBarItem4 = [tabBar.items objectAtIndex:3];
UITabBarItem *tabBarItem5 = [tabBar.items objectAtIndex:4];
if (![[NSUserDefaults standardUserDefaults] objectForKey:@"first"]) {
//first launch selected third tabBarItem
tabBarController.selectedIndex = 2;
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"first"];
}