サーバー出力をチェックして「false」かどうかを確認するログインページで、false でない場合は、メインビューコントローラークラスに移動するためのこのコードを追加しますが、以下のコードは機能しません。
ViewController *main = [self.storyboard instantiateViewControllerWithIdentifier:@"App"];
[self.navigationController pushViewController:main animated:YES];
私のセグエ名は「App」で、メインのviewController IDも「App」です。
URL 要求の送信とサーバー応答の取得に使用されるコード stringValue には自分の URL が含まれています
NSMutableURLRequest *request =[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString: stringValue]];
request.HTTPMethod = @"POST";
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
request.HTTPBody = myRequestData;
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString * serverOutput= [[NSString alloc]initWithData:data encoding:NSASCIIStringEncoding];
NSLog(@"%@",serverOutput);
if(serverOutput!=NULL)
{
if([serverOutput isEqualToString:@"login"])
{
[self performSegueWithIdentifier:@"App" sender:self];
}
else
{
NSError *jsonError = nil;
id mylibrary = [NSJSONSerialization JSONObjectWithData:[serverOutput dataUsingEncoding:NSUTF8StringEncoding]options:0 error:&jsonError];
NSDictionary *ratedBookList = [(NSDictionary*)mylibrary objectForKey:@"library"];
[self saveMylibrary:ratedBookList];
}
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle: nil];
ViewController *main = [self.storyboard instantiateViewControllerWithIdentifier:@"App"];
[self.navigationController pushViewController:main animated:YES];
[alertView dismissWithClickedButtonIndex:0 animated:YES];
}
} ];
_alertView = [[UIAlertView alloc] initWithTitle:@"Please Wait..."
message:@"\n"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil];
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.center = CGPointMake(120, 75.5);
[alertView addSubview:activityIndicator];
[activityIndicator startAnimating];
[alertView show];
}