Objective c Obj-C:我有'addTarget:action:forControlEvents',但目标没有响应选择器

Objective c Obj-C:我有'addTarget:action:forControlEvents',但目标没有响应选择器,objective-c,uiviewcontroller,selector,uigesturerecognizer,uicontrol,Objective C,Uiviewcontroller,Selector,Uigesturerecognizer,Uicontrol,我创建了一个类SYFactory,其中包含用于组装对象的各种类方法(主要是UIViews和UIControls)。这些类方法由UIViewController对象调用(或者更准确地说,由名为SYViewController的UIViewController子类的实例调用) 我正在尝试将选择器添加到由SYFactory创建的UIControl对象,目标设置为SYViewController的实例 因此,在SYFactory中: + (UIControl*)replyPaneWithWidthFro

我创建了一个类
SYFactory
,其中包含用于组装对象的各种类方法(主要是
UIView
s和
UIControl
s)。这些类方法由
UIViewController
对象调用(或者更准确地说,由名为
SYViewController
UIViewController
子类的实例调用)

我正在尝试将选择器添加到由
SYFactory
创建的
UIControl
对象,目标设置为
SYViewController
的实例

因此,在
SYFactory
中:

+ (UIControl*)replyPaneWithWidthFromParent:(UIView*) parent selectorTarget:(id) target
{
//...
    [replyPane addTarget:target
                  action:@selector(showTheVideoPane:)
        forControlEvents:UIControlEventTouchUpInside];

    return replyPane;
}
UIViewController
子类(称为
SYViewController
)中:

当我运行代码并尝试点击我创建的
UIControl
时,我得到一个
未识别的选择器发送到实例
错误。我不知道为什么,因为我将
SYViewController
对象作为参数传递到
+replyPaneWithWidthFromParent:parent Selector或target:target

出于某种奇怪的原因,
UIControl
对象认为消息不应该发送到
SYViewController
对象,并尝试将其发送到不同类别的对象。奇怪吧

有什么建议吗

编辑:

因此,在发布问题后,我马上发现了问题所在(这是另一个证据,证明写下来有助于思考问题!):

SYViewController
对象是在
for
循环内部的局部变量中创建的。没有对对象的进一步引用,一旦
for
循环终止,
SYViewController
对象被ARC破坏

面对不存在的目标,
UIControl
对象试图在响应者链中找到它认为最有可能响应消息的对象。该对象属于类
SYFixedMarginView
,因此错误消息:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'-[SYFixedMarginView showTheVideoPane:]: unrecognized selector sent to instance 0x1f877d60'
因此,解决方法很简单。除了
for
循环中的局部变量之外,我还将视图控制器分配给了
\u strong
属性


希望其他人不要落入同样的陷阱。

错误应该是选择器发送到哪个类;上面说什么?请粘贴整个错误。它说的是
SYFixedMarginView
,这是
UIView
的一个子类。实际上我刚刚弄明白它是什么,答案马上就来了。显然我无法回答我自己的问题,因为没有足够的Stackoverflow帖子,所以我在问题中提供了答案
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'-[SYFixedMarginView showTheVideoPane:]: unrecognized selector sent to instance 0x1f877d60'