2014-02-10 100 views
1

在我的应用程序中,我有5个导航标签。UITabbarController设置初始视图

但是我希望我的中间选项卡(选项卡3)是第一次加载应用程序时首先显示的选项卡。

有没有办法做到这一点?

+0

tabBarController.selectedIndex = 2;简单 – Pawan

回答

2

首次加载意味着有史以来第一次?或每次新推出?这个代码是第一次,但没有NSUserDefault可用于每一个新的发射

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"]; 

    } 
+1

谢谢你的帮助 – Khledon