在我的登录页面中,当我检查服务器输出以查看它是否为“假”时,如果它不是假的,我添加此代码以移动到主视图控制器类,但以下代码对我不起作用。
ViewController *main = [self.storyboard instantiateViewControllerWithIdentifier:@"App"];
[self.navigationController pushViewController:main animated:YES];
请帮帮我,我的 segue 名称是“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];
}