按钮触摸仅有效一次

发布于 2024-12-03 10:14:36 字数 1175 浏览 0 评论 0原文

由于某种原因,与我的 UIButton 的交互只能进行一次。我已经通过 IBAction 和 IBOutlet 与“addTarget”进行了尝试。我不知道为什么。

Context:

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];

该类只是弹出一个消息框,获取用户输入,然后回调视图控制器:

(Inside SomeOtherClass):

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

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

在一个流行 BBS 论坛上的帖子中,有人提到像这样的问题可能是由于没有您认为拥有的对象 (vc1) 而导致的,而是由它的另一个实例引起的。因此,我在很多地方记录了像 NSLog("instance: %p", self) 这样的实例,而且它总是相同的。

任何想法都将不胜感激。这非常令人沮丧。

For some reason, interaction with my UIButton only works once. I've tried both via IBAction, and by IBOutlet with "addTarget". I have no idea why.

Context:

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

Also, this is where I try "addTarget" but that doesn't work either (first touch works, but not the second)

In the "button_touched" method of ViewController1 (vc1), I make a call to another class like this:

[someOtherClassObject doSomethingWithMyView:self];

That class simply pops up a message box, gets user input, then calls back on the viewcontroller:

(Inside SomeOtherClass):

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

Once this workflow has executed once, the button touch never calls the "button_touch" method again. No matter what I do, I can't get this to be called again.

In a thread on one of the popular BBS forums, someone mentioned that a problem like this could be caused by not having the object (vc1) you think you do, but rather, another instance of it. So, I logged the instance like NSLog( "instance: %p", self) in numerous places, and it's always the same.

Any ideas are greatly appreciated. This is very frustrating.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月竹挽风 2024-12-10 10:14:36

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

在你的陈述之后尝试:

[vc userInputReceived:TRUE];

添加行

[[UIApplication sharedApplication].keyWindow makeFirstResponder:vc.view];

shot in the dark maybe, but its possible that your view controller's view has lost first responder status due to the displaying of the message inside the other object (what type of object is this and how is the message displayed?).

Try after your statement:

[vc userInputReceived:TRUE];

adding the line

[[UIApplication sharedApplication].keyWindow makeFirstResponder:vc.view];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文