ここにボタンがあります。この関数の最後で、別のビュー コントローラーに切り替えたいと思います。ただし、切り替える方法がわかりません。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;
}
}
どんな助けでも大歓迎です!
ありがとう!