如何以编程方式触发 IBAction 方法,而不是通过按钮等?
通过创建 IBAction 方法并将其连接到 IB 中的按钮,我可以轻松地“做某事”。例如...
-(IBAction)popThat:(id)sndr{ [windy setFrame:eRect display:YES];}
但是,我无法,在我的一生中,弄清楚如何通过简单的可调用方法来做到这一点...即
-(void) popThatMethod { [windy setFrame:eRect display:YES]; }
-(void) awakeFromNib { [self popThatMethod]; }
我会 >期望此方法会执行与单击按钮相同的操作...因为它们是相同的...但是没有。什么也没发生。 我在这里缺少什么?
I can easily "do something", by creating an IBAction method, and connecting it to a button in IB. For example...
-(IBAction)popThat:(id)sndr{ [windy setFrame:eRect display:YES];}
However, I cannot, for the life of me, figure out how to do this via a simple, callable method... i.e.
-(void) popThatMethod { [windy setFrame:eRect display:YES]; }
-(void) awakeFromNib { [self popThatMethod]; }
I would expect that this method would DO the same thing as clicking the button... as they are identical... but NO. Nothing happens. What am I missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我并没有说这绝对是最好的答案,或者是正确的方法,但一种有效的方法是将以下内容放入
-applicationDidFinishLaunching:
中:这会导致它被调用运行循环的下一次传递,此时之前未到位的内容现在已就位。
I don't state that this is categorically the best answer, or the right way to do it, but one approach that works is to put the following in
-applicationDidFinishLaunching:
:This causes it to be called on the next pass of the runloop, by which time whatever was not in place before is now in place.
根据您想要执行的操作,您可能希望
Which 触发按钮,就像它被触摸一样,并强制执行与之相关的任何操作。
注意:这是我询问 这个问题。
Depending on what you're trying to do, you might want
Which triggers the button as if it had been touched, and forces whatever actions are connected to it.
NOTE: that's the answer from when I asked this SO question.