我正在尝试构建一个成功登录后重定向到主页的应用程序。我有两个视图控制器:LoginViewController
和DashboardViewController
. 我已经对登录部分进行了编码,并为仪表板创建了一个视图,但我不确定如何重定向到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];
}
@结尾