Ios 从ConnectionIDFinishLoading调用PerformsgueWithIdentifier时出现问题

Ios 从ConnectionIDFinishLoading调用PerformsgueWithIdentifier时出现问题,ios,objective-c,Ios,Objective C,我有一个登录屏幕,当按下按钮时,此代码执行: - (IBAction)btnLogin:(id)sender { [username resignFirstResponder]; [password resignFirstResponder]; Auth *authRequest = [[Auth alloc] init]; NSURL *url = [[NSURL alloc] initWithScheme:@"http" host:APIHOST p

我有一个登录屏幕,当按下按钮时,此代码执行:

- (IBAction)btnLogin:(id)sender {
    [username resignFirstResponder];
    [password resignFirstResponder];


    Auth *authRequest = [[Auth alloc] init];



    NSURL *url = [[NSURL alloc] initWithScheme:@"http" host:APIHOST path:@"/authenticate"];
    [authRequest setUrl:url];
    [authRequest setUsername:[username text]];
    [authRequest setPassword:[password text]];
    [authRequest authenticate];

    [self performSegueWithIdentifier:@"Login2Tab" sender:self];


}
这很好,segue按预期执行(因此我知道segue存在,并且在故事板中正确识别了它)。但是,在连接完成加载之前,我不想执行segue,因此此实现文件是NSURLConnection的委托,在底部我有(并且响应代码上的if/else有效)…:

(当我将performsguewithidentifer放入connectiondFinishLoading时,我从上面注释掉performsguewithidentier…)

但现在该应用程序总是崩溃,并声明:

*由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因是:“接收器(LoginViewController:0x7163640)没有标识符为“Login2Tab”的序列。


这就是我被卡住的地方,因为它在没有从ConnectiondFinishLoading中调用时工作…

只是想说我已经解决了这个问题,尽管我不完全确定如何解决

基本上,我的ViewController中的这一行

[authRequest authenticate];
正在外部类文件中加载方法:

- (void)authenticate {
    NSURL *url = [[NSURL alloc] initWithScheme:@"http" host:APIHOST path:@"/authenticate"];

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:3];
    NSString *postString = [[NSString alloc] initWithFormat:@"email=%@&password=%@", [username text], [password text]];

    [request setValue:APIKEY forHTTPHeaderField:@"apikey"];
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
    [request setURL:url];


    if ([NSURLConnection canHandleRequest:request]) {
        NSLog(@"Starting network connection");
        NSURLConnection *myConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
        [myConnection start];
    } else {
        //Error cannot activate network request from device
    }
}
NSURLConnection的代理位于viewcontroller中。。。当方法完成时,我可以看到它们被访问,但是我无法从它们执行segue。通过将此函数从类文件移动到我的viewcontroller,我能够从ConnectiondFinishLoading的委托方法调用我的segue


奇怪但有效。

这两种方法(
btnLogin:
connectiondFinishLoading:
)是在同一个类(
LoginViewController
)中实现的吗?你试过来自@Guillaume的建议吗?是的,它们都是在LoginViewController中实现的。m@Corey,刚尝试了那篇文章中的所有内容。。。。不走运。让我抓狂,因为它在未从该连接调用时工作IDFinishLoading。。。所以我知道它的设置是正确的,只是不知道为什么它不能从委托方法中看到segue…你确定segue同时存在于iPhone和iPad故事板上吗?您可能正在使用另一个不存在segue的服务器?
- (void)authenticate {
    NSURL *url = [[NSURL alloc] initWithScheme:@"http" host:APIHOST path:@"/authenticate"];

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:3];
    NSString *postString = [[NSString alloc] initWithFormat:@"email=%@&password=%@", [username text], [password text]];

    [request setValue:APIKEY forHTTPHeaderField:@"apikey"];
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
    [request setURL:url];


    if ([NSURLConnection canHandleRequest:request]) {
        NSLog(@"Starting network connection");
        NSURLConnection *myConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
        [myConnection start];
    } else {
        //Error cannot activate network request from device
    }
}