单击按钮时无法识别的选择器发送到实例错误 [英] unrecognized selector sent to instance error when a button is clicked

查看:22
本文介绍了单击按钮时无法识别的选择器发送到实例错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不完全确定为什么会收到此错误.当我单击 FirstViewController 上的按钮时会发生这种情况:

I'm not entirely sure why I am getting this error. It occurs when I click the button on my FirstViewController:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FirstViewController 1ButtonPress:]: unrecognized selector sent to instance 0x10954bbd0'

我的 FirstViewController 有一个按钮 (1ButtonPress),它与另一个具有嵌入 NavigationController 的 ViewController 执行转场(所以在我的故事板中,转场是从 FirstViewController 到 NavigationController).在此转场中,一些数据通过以下方式传输到另一个 ViewController:
第一.m

My FirstViewController has a button (1ButtonPress) which performs a segue with another ViewController which has a embed NavigationController (so in my storyboard, the segue is from FirstViewController to the NavigationController). On this segue, some data is transferred to the other ViewController by:
First.m

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"abc"]) {
            UINavigationController *navController = [segue destinationViewController];
            SecondViewController *BVC = (SecondViewController *)(navController.topViewController);
        BVC.BLLImg = [UIImage imageNamed:@"SomeImage.jpg"];
        BVC.BLLTitle = @"SomeText";
    }

}

segue 在故事板中具有标识符abc".环顾四周,我相信它与不正确的类有关,但第一次检查时一切看起来都很好.
我会收到此错误的任何其他原因?

The segue has the identifier "abc" in storyboard. Looking around it, I believe it has something to do with an incorrect class, but everything on first inspection looks fine.
Any other reason why I would be getting this error?

推荐答案

让我们回顾一下您看到的错误.它说一个无法识别的选择器被发送到 FirstViewController 的一个实例.

Let's go through the error you saw. It says that an unrecognized selector was sent to an instance of FirstViewController.

根据我的推断,您将按钮连接到视图控制器,稍后从视图控制器中删除实现,假设它会删除您之前从按钮到视图控制器创建的连接.不幸的是,这不是它的工作方式.您也需要从按钮中删除连接.

From what I deduce, you hooked up your button to your view controller, and removed the implementation from your view controller later, assuming that it'd remove the connection you earlier created from your button to your view controller. Unfortunately, that's not how it works. You need to remove the connection from the button too.

为此,请右键单击情节提要中的按钮,然后移除显示 1ButtonPress: 的连接.

To do that, right click on your button in the storyboard, and remove the connection which says 1ButtonPress:.

旁注:您做的太多,初学者无法理解.请尝试一步一步地穿越可可世界.另外,请阅读这篇文章以了解如何以更易于理解的方式命名方法和变量.

Side note: You're doing too much for a beginner to understand. Please try going through the Cocoa world step by step. Also, read up this article to learn about how to name your methods and variables in a more easy-to-understand way.

这篇关于单击按钮时无法识别的选择器发送到实例错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆