2

我有一个登录屏幕,用于检查插入的密码是否正确。

之后,我想从登录屏幕切换到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登录成功时...

4

2 回答 2

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 及更高版本制作应用程序,则最好使用第一行,这样您以后就不必进行更改。

如果您想使用 nib 文件执行上述代码,则使用情节提要,然后更改

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

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

希望这可以帮助。

于 2013-02-14T10:23:08.847 回答
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];
}
于 2013-02-14T10:11:16.447 回答