【问题标题】:ios segue unrecognized selector sent to instanceios segue 无法识别的选择器发送到实例
【发布时间】:2014-06-29 15:13:40
【问题描述】:

我正在开发一个 iOS 应用程序,但在测试过程中遇到了一个问题:当我尝试进入下一个 ViewController 时应用程序崩溃并收到以下消息:

2014-06-29 14:22:46.674 IOS2 Practica[55472:60b] -[Logger login:]: unrecognized selector sent to instance 0x9242230
2014-06-29 14:22:46.679 IOS2 Practica[55472:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Logger login:]: unrecognized selector sent to instance 0x9242230'

从我查过的其他案例来看,当我尝试使用“segue”切换到下一个 ViewController 但我无法确定确切的来源时,可能会发生某些事情。

我在我的主视图控制器中附加了定义 segue 的代码段:

- (void)logger:(id)sender {
    NSString *user = self.username.text;
    NSString *pass = self.password.text;

    NSString * urlBase = @"http://www.v2msoft.com/clientes/lasalle/curs-ios/login.php?username=lluis&password=seguro";

    [JSONHTTPClient getJSONFromURLWithString:urlBase completion:^(id json,JSONModelError *err){

        JsonUser * user = [[JsonUser alloc]initWithDictionary:json error:nil];

        if(user.succeed) {
            self.user_id = user.user_id;

            [self performSegueWithIdentifier:@"Login" sender:self];
         } else {
             NSLog(@"error");
        }
     }];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if (_username.text.length == 0 || _password.text.length == 0) {
        [[[UIAlertView alloc] initWithTitle:@"Error"
                                    message:@"Algun dels camps és incorrecte o està buit!"
                                   delegate:self
                          cancelButtonTitle:@"Cancel"
                          otherButtonTitles:nil, nil]
         show];

    } else {
        Supermarket * supermercat = segue.destinationViewController;
        supermercat.user_id = self.user_id;
    }

}

提前感谢您对此主题的任何见解。

【问题讨论】:

  • 你是否在故事板中设置了标识符为“Login”的segue?
  • 是的。我检查的第一件事。我有segues,我确实检查了名称是否匹配。所以不是这样。感谢您的建议。

标签: ios segue unrecognized-selector


【解决方案1】:

在您的代码中的某处(不是您发布的部分),您应该在 Logger 实例上调用 login: 方法。该方法未在 Logger 中定义,这就是应用崩溃的原因。

注意Login: 末尾的::可能你已经定义了一个login 方法(它不带任何参数),但是你正在用一个参数调用它。或者您可能想致电logger:

您可以尝试 2 件事:要么找出调用 login: 方法的位置(在 Storyboard 中绑定了某个按钮?),要么将 logger: 重命名为 login:

【讨论】:

    猜你喜欢
    • 2014-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-07
    • 1970-01-01
    • 2012-09-18
    • 1970-01-01
    • 2019-08-28
    相关资源
    最近更新 更多