按钮触摸只能工作一次

时间:2011-09-08 22:13:54

标签: iphone ios uibutton target ibaction

出于某种原因,与我的UIButton的互动仅适用一次。我已经通过IBAction和IBOutlet尝试了“addTarget”。我不明白为什么。

上下文:

BaseViewController

- (IBAction) button_touched:(id)sender; //<-- Declared here, but not implemented
- (void)userInputReceived:(BOOL)bSuccess; //<-- Declared here, but not implemented

ViewController1:BaseViewController

- (IBAction) button_touched:(id)sender; //<-- Implemented here
- (void)userInputReceived:(BOOL)bSuccess; //<-- Implemented here

此外,这是我尝试“addTarget”的地方,但这也不起作用(第一次触摸工作,但不是第二次)

在ViewController1(vc1)的“button_touched”方法中,我调用另一个这样的类:

[someOtherClassObject doSomethingWithMyView:self];

该类只是弹出一个消息框,获取用户输入,然后在viewcontroller上回调:

(Inside SomeOtherClass):

-(void)doSomethingWithMyView:(BaseViewController*)vc
{
    // Do Something
    [vc userInputReceived:TRUE];
}

一旦此工作流程执行一次,按钮触摸再也不会调用“button_touch”方法。无论我做什么,我都无法再次召唤它。

在一个流行的BBS论坛上的一个帖子中,有人提到像这样的问题可能是因为没有你认为你做的对象(vc1),而是另一个它的实例。因此,我在许多地方记录了像NSLog(“instance:%p”,self)这样的实例,它总是一样的。

非常感谢任何想法。这非常令人沮丧。

1 个答案:

答案 0 :(得分:0)

也许在黑暗中拍摄,但是由于在另一个对象内部显示消息,你的视图控制器的视图可能已经失去了第一响应者状态(这是什么类型的对象以及消息是如何显示的?)。 / p>

试试你的陈述:

[vc userInputReceived:TRUE];

添加行

[[UIApplication sharedApplication].keyWindow makeFirstResponder:vc.view];
相关问题