从另一个按钮更改一个按钮的标题 IBAction
以编程方式创建 UIbuttons 时,是否可以从另一个 UIbuttons IBAction 方法访问 UIbutton?我能够使用界面生成器通过为每个按钮创建一个 IBOutlet 并以这种方式引用它们来完成此操作,但我需要以编程方式创建按钮,并且似乎无法弄清楚这是否可能?
谢谢!
Is there anyway to access a UIbutton from another UIbuttons IBAction method when creating the UIbuttons programmatically? I was able to do this using interface builder by creating an IBOutlet for each of them and referencing them that way, but I need to create the buttons programmatically and can't seem to figure out if this is possible?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建按钮时,将它们分配给控制器中的 ivars。然后您的 IBAction 方法可以根据需要访问这些 ivars 中的任何一个。
例如,在您的视图控制器标头中,您可能有:
在您的实现中,您将创建如下所示的按钮:
然后在您的 IBAction 方法中,您可能会执行如下操作:
有意义吗? (这都是从内存中编码的,未经测试,fwiw。)
When you create the buttons, assign them to ivars in your controller. Then your IBAction methods can access any of these ivars as needed.
For example, in your view controller header you might have:
In your implementation you would create your buttons something like this:
Then in your IBAction method you might do something like this:
Make sense? (This is all coded from memory and not tested, fwiw.)