无法识别的选择器发送到实例

时间:2011-04-30 16:45:39

标签: objective-c

XCode让我疯狂(再次)。人们如何使用它?

-[UIViewController look_for_offer:]: unrecognized selector sent to instance 0x4e34220
2011-04-30 18:38:25.207 myApp[8261:40b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController look_for_offer:]: unrecognized selector sent to instance 0x4e34220'

这就是我的所作所为。我按了一个按钮。我点击了按钮,然后转到检查器中的“连接”选项卡。我从触摸事件拖到代码,它自动创建一个空方法和方法标题。这是方法:

- (IBAction)look_for_offer:(id)sender {

}

现在记住,我甚至没有写过。 Interface Builder为我生成了它。然而,当我构建并单击按钮时,我收到“无法识别的选择器”错误消息。

它从错误消息中看起来就像他正在尝试将消息look_for_offer发送到UIViewController。我不知道为什么他会这样做。该方法在我看来,它是UIViewController的子类:

@interface ClientSeekingView : UIViewController {

}

- (IBAction)look_for_offer:(id)sender;

我清楚地将动作拖入了类代码,而不是UIViewController。为什么他试图将消息发送到UIViewController而不是我的类?

我做错了什么?我如何取悦Xcode? PS:我多次清理和重建,没有帮助。

MRB

1 个答案:

答案 0 :(得分:9)

看起来您没有将Interface Builder File's Owner对象更改为您自己的类。 IB创建了UIViewController类型的对象,而不是ClientSeekingView。错误消息表明您的选择器正在发送到类UIViewController的对象。

要更改班级,您可以使用 Identity Inspector Identity Inspector Menu Item

相关问题