1

我正在尝试构建一个成功登录后重定向到主页的应用程序。我有两个视图控制器:LoginViewControllerDashboardViewController. 我已经对登录部分进行了编码,并为仪表板创建了一个视图,但我不确定如何重定向到DashboardViewController成功登录后。我真的很感激一些帮助。

这是我的LoginViewController.m文件代码:

#import "LoginViewController.h"

@implementation LoginViewController

@synthesize userName,password,loginbutton,indicator;

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


- (IBAction) loginButton: (id) sender
{
    // TODO: spawn a login thread

    indicator.hidden = FALSE;
    [indicator startAnimating];
    NSString *post =[NSString stringWithFormat:@"username=%@&password=%@",userName.text, password.text];

    NSString *hostStr = @"******";
    hostStr = [hostStr stringByAppendingString:post];
    NSData *dataURL =  [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];
    NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
    //NSLog(@"Result = '%@'", serverOutput); // look for space between quotes
    serverOutput = [serverOutput stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];



    if([serverOutput isEqualToString:@"Yes"]){


        UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Congrats" message:@"You are authorized"
            delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

        [alertsuccess show];
        [alertsuccess release];


        }
    else {
        UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Username or Password Incorrect"
            delegate:self cancelButtonTitle:@"OK"otherButtonTitles:nil, nil];
        [alertsuccess show];
        [alertsuccess release];
        loginbutton.enabled = TRUE;

    }


    loginbutton.enabled = FALSE;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [self.userName resignFirstResponder];
    [self.password resignFirstResponder];

}

@结尾

4

2 回答 2

3

首先#import "DashboardViewController.h"在你的文件中添加loginViewContrller.m文件

并创建DashboardViewControllerin 的对象

if([serverOutput isEqualToString:@"Yes"])
{
       DashboardViewController *newView = [[DashboardViewController alloc] init];
       [self presentModalViewController:newView animated:YES];

        UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Congrats" message:@"You are authorized"
            delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

        [alertsuccess show];
        [alertsuccess release];

}
于 2013-04-18T03:52:08.517 回答
1

1) 设置tagalertalertsuccess.tag = 1;

2)使用以下代码显示下一个ViewController

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag == 1 && buttonIndex == 0)
    {
         DashboardViewController *vcDashboard = [[DashboardViewController alloc] init];
         if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0)
         {
             [self presentViewController:vcDashboard animated:YES completion:nil];
         }
         else
         {
             [self presentModalViewController:vcDashboard animated:YES];
         }
         [vcDashboard release];
    }
}
于 2013-04-18T04:15:29.547 回答