2013-02-14 362 views
2

我有一個登錄屏幕,用於檢查插入的密碼是否正確。從登錄屏幕到`UITabBarController`

之後,我想從登錄屏幕切換到UITabBarController。從LoginViewController.m

代碼:

-(IBAction)LoginButton:(id)sender { 

    [PassWortEingabe resignFirstResponder]; 
    NSString *pnssPasswortEingabe = [NSString stringWithFormat:@"%@",PassWortEingabe.text]; 
    NSString *pnssPasswortString = [NSString stringWithFormat:@"%s","Hallo"]; 

    if([pnssPasswortEingabe isEqualToString: pnssPasswortString ]){ 

     DebugTextView.text = @"Login succesfull"; 
     //PassWortEingabe = 0; 
     //[PassWortEingabe resignFirstResponder]; 
    }else{ 

     DebugTextView.text = @"Login unsuccesfull"; 
     //PassWortEingabe = 0; 
     //[PassWortEingabe resignFirstResponder]; 
    } 


} 

我想跳到UITabBarController當登錄SUCESSFUL ...

回答

0
if([pnssPasswortEingabe isEqualToString: pnssPasswortString ]){ 

    DebugTextView.text = @"Login succesfull"; 
    MyTabBarClass *myTabBar = [[MyTabBarClass alloc]initWithNibName:nil bundle:nil]; 
    myTabBar.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
    [self presentModalViewController:myTabBar animated:YES]; 
    //PassWortEingabe = 0; 
    //[PassWortEingabe resignFirstResponder]; 
}else{ 

    DebugTextView.text = @"Login unsuccesfull"; 
    //PassWortEingabe = 0; 
    //[PassWortEingabe resignFirstResponder]; 
} 
0

這是因爲下面的代碼一樣簡單。

if([pnssPasswortEingabe isEqualToString: pnssPasswortString ]){ 
    // This is for iOS 5.0 and above. 
    UITabBarController *myTabBarController = [self.storyboard instantiateViewControllerWithIdentifier:@"myTabBarController"]; 
    [myTabBarController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; 
    [self presentViewController:myTabBarController animated:YES completion:^(void){ 
     // You can set some sort of completion block here which will run when all other code finishes, this can just be nil. 
    }]; 
} else { 
    DebugTextView.text = @"Login unsuccesfull"; 
} 

您也可以替換該行與

[self presentViewController:myTabBarController animated:YES completion:nil]; 

[self presentModalViewController:myTabBarController animated:YES]; 

取代,但這已經在iOS的6.0被棄用。因此,如果您要爲iOS 5.0及更高版本製作應用程序,則最好使用第一行,以便您不必在將來進行更改。

上面的代碼是由如果你想與筆尖的文件做然後改變

[self.storyboard instantiateViewControllerWithIdentifier:@"myTabBarController"]; 

[[UITabBarController alloc] initWithNibName:@"myTabBarController" bundle:[NSBundle mainBundle]]; 

希望這有助於用故事板。

+0

爲什麼不直接在故事板中使用segue? – Dejell 2013-02-20 19:54:01

+0

@Odelya毫無理由。我只是喜歡用代碼來完成。 – Popeye 2013-02-20 20:29:10