2012-11-05 42 views
1

在我AppDelegate.m如何登錄Iphone App後重定向到主頁選項卡?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

    NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; 
    //Get uer ID from user defaults 
    NSString *userid = [defaults objectForKey:@"UserId"]; 

    if([userid isEqualToString:@""]){ 

     login = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil]; 
     [window addSubview:login.view]; 


    } else { 

     [window addSubview:[rootTabBarController view]]; 

    } 

    [self.window makeKeyAndVisible]; 
    return YES; 
} 

後登錄成功,我有這樣的代碼

NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; 
[defaults setObject:serverOutput forKey:@"UserId"]; 
//show tabbar app 
NewClassMoonAppDelegate * appsDelegate =[[UIApplication sharedApplication] delegate]; 
[appsDelegate.window addSubview:[appsDelegate.rootTabBarController view]]; 

這樣的問題是如何可以重定向到特定的標籤[主頁選項卡EXAMBLE]

回答

1
[appDelegate.rootTabBarController setSelectedIndex:GiveIndexOfTab]; // give index of home tab for ex. 0 
+0

對不起,我是初學者在ios ..你可以做更多的討論..我什麼時候可以,但我上面的代碼這行上 –

+0

當你想在當時以編程方式更改tabbar視圖只是寫上面這行.. –

1

如果你想跳轉到一個特定的標籤,而不攔截的TabBar,而不是第一個默認選項卡

使用

[appsDelegate.rootTabBarController setSelectedIndex:2]; // 2 is a pseudo index i have assigned 
+0

謝謝..它現在很好。 –

0

有關的TabBar控制器,

的SelectedIndex屬性格式幫助你管理它的行爲。

使用

setSelectedIndex:Index 

方法。它會解決你的目的。

謝謝。

相關問題