在我的登录页面中,当我检查服务器输出以查看它是否为“false”时,如果它不是false我添加此代码以移动到主viewcontroller类 但是下面的代码对我不起作用。
ViewController *main = [self.storyboard instantiateViewControllerWithIdentifier:@"App"];
[self.navigationController pushViewController:main animated:YES];
请帮帮我,我的segue名称是“App”,主viewController id也是“App”。
用于发送网址请求和获取服务器响应的CODE stringValue包含我的网址
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];
}
答案 0 :(得分:0)
确保StoryboardID
正确且唯一
确保self.storyboard具有有效内存并且具有VC
例如
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
ViewController *lvc = [storyboard instantiateViewControllerWithIdentifier:@"App"];
[self.navigationController pushViewController:lvc animated:YES];