1

在我的登录页面中,当我检查服务器输出以查看它是否为“假”时,如果它不是假的,我添加此代码以移动到主视图控制器类,但以下代码对我不起作用。

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];


}
4

1 回答 1

0

确保StoryboardID正确且唯一

确保 self.storyboard 有有效的内存并且它有 VC

例如

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil]; 
ViewController *lvc = [storyboard instantiateViewControllerWithIdentifier:@"App"];
[self.navigationController pushViewController:lvc animated:YES];
于 2013-05-16T12:28:45.343 回答