IBAction 是否必须反映 Interface Builder 上的方法?

发布于 2024-12-01 10:52:51 字数 239 浏览 0 评论 0原文

下面两种方法有什么区别,两者都是通过 Interface builder 进行映射的,

- (void) showNYTimes:(id)sender
          and 
- (IBAction) showNYTimes:(id)sender

两者都非常适合我的要求,我能够在 IB 上映射这两种方法。但是选择哪一个,IBAction 仅仅是为了代码的可读性吗?

谢谢。

What is the difference between below two methods, both are meant for mapping through Interface builder

- (void) showNYTimes:(id)sender
          and 
- (IBAction) showNYTimes:(id)sender

Both are working perfectly for my requirement, I am able to map both ways on IB. But which one to opt, is IBAction meant for only readability of code?

Thanks.

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

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

发布评论

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

评论(1

(り薆情海 2024-12-08 10:52:51

IBAction#define 定义为 void,因此就 Objective C 而言,它们是相同的;它意味着向 Interface Builder 发出一个信号,表明该特定方法可以连接到视图。 "IBAction - 使用的类型限定符通过 Interface Builder 将以编程方式添加的操作与其为项目定义的内部操作方法列表进行同步。”

因此,它不仅仅是可读性;这是一个对 IB 有意义的声明。不过,我不确定您如何在 Interface Builder 中映射您的 (void) 方法。只有 (IBAction) 方法对我来说有一个小圆圈。

IBAction is #defined as void, so as far as Objective C is concerned they're the same; it's meant to be a signal to Interface Builder that this particular method is available to be hooked up to a view. "IBAction - Type qualifier used by Interface Builder to synchronize actions added programmatically with its internal list of action methods defined for a project."

So it's more than just readability; it's a declaration that's meaningful to IB. I'm not sure how you were able to map your (void) method in Interface Builder, though. Only (IBAction) methods have the little circle in the gutter for me.

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