我在这里有我的按钮,在这个功能结束时我想切换到另一个视图控制器。但是我不知道如何切换它,我只为应用程序的 iphone 版本工作。
- (IBAction)loginMe:(UIButton *)sender {
[self.view endEditing:YES];
NSURL *url = [NSURL URLWithString:@"http://192.168.1.111:8888/api.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
NSString *requester = [NSString stringWithFormat:@"type=account&username=%@&password=%@",self.username.text,self.password.text];
NSData *requestBody = [requester dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:requestBody];
NSURLResponse *response = NULL;
NSError *requestError = NULL;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&requestError];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
if([responseString isEqualToString:@"1"])
{
self.data.text = @"Username or password incorrect";
}
else
{
NSData* data = [responseString dataUsingEncoding:NSUTF8StringEncoding];
NSError *jsonParsingError = nil;
NSArray *publicTimeline = [NSJSONSerialization JSONObjectWithData:data
options:0 error:&jsonParsingError];
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
[ud setInteger:1 forKey:@"isLoggedin"];
[ud setObject:[publicTimeline objectAtIndex:0] forKey:@"userid"];
[ud setObject:[publicTimeline objectAtIndex:1] forKey:@"username"];
[ud setObject:[publicTimeline objectAtIndex:2] forKey:@"loginstr"];
[ud synchronize];
[self animateLoginBox];
self.data.text = responseString;
}
}
任何帮助将非常感激!
谢谢!