【发布时间】:2013-06-27 13:51:36
【问题描述】:
我有一个登录屏幕,当按下按钮时,此代码会执行:
- (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 委托,并且在底部我有(并且 responseCode 上的 if/else 确实有效)..:
// Close the connection
- (void)connectionDidFinishLoading:(NSURLConnection*)connection {
if(responseCode == 200) {
[self performSegueWithIdentifier:@"Login2Tab" sender:self];
} else {
NSLog(@"Bad.. bad.. bad...");
}
NSLog(@"Connection Closed.");
}
(当我将 performSegueWithIdentifer 放在 connectionDidFinishLoading 中时,我从上面注释掉 performSegueWithIdentier...)。
但现在应用程序总是崩溃说明:
* 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“接收方(LoginViewController:0x7163640)没有与标识符“Login2Tab”的segue”
这是我卡住的地方,因为当它没有从 connectionDidFinishLoading 中调用时它可以工作......
【问题讨论】:
-
这两个方法(
btnLogin:和connectionDidFinishLoading:)是在同一个类(LoginViewController)中实现的吗? -
你试过this post的建议了吗?
-
@Guillaume 是的,它们都在 LoginViewController.m 中实现
-
@Corey,刚刚尝试了该帖子中的所有内容......没有运气。让我发疯,因为它在没有从该 connectionDidFinishLoading 调用时工作......所以我知道它的设置是正确的,只是不确定为什么它不能从委托方法中看到 segue......
-
您确定 iPhone 和 iPad 故事板上都存在 segue 吗?可能您正在使用另一种不存在 segue 的方法?
标签: ios objective-c