我应该把IBActions在头文件或不是? [英] Should I put IBActions in the header file or not?

查看:159
本文介绍了我应该把IBActions在头文件或不是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于iOS SDK 6.1在Xcode 4.6.3中使用,是否会在头文件中声明 IBAction 的方法签名是否有区别?

Given that iOS SDK 6.1 is used in Xcode 4.6.3 , does it make a difference to declare the method signature of IBAction in a header file or not?

没有在头文件中放置方法声明,应用程序仍然能够编译和运行没有问题。但是,该方法不能在故事板中看到。

Without putting the method declaration in the header file, the app is still able to compile and run without problems. However, the method cannot be seen in a storyboard.

在头文件中没有声明方法的隐藏问题吗?是否有内存消耗差异?

Are there any hidden issues of not declaring the method in the header file? Is there a memory consumption difference?

推荐答案

IBAction 方法是在Interface Builder(使用Storyboards或不使用Storyboards)中的 public 连接点。

The entire point of an IBAction method is to be a public connection point in Interface Builder (using Storyboards or not).

IBAction 本身是 #define d as void 。它的唯一目的(和 IBOutlet 相同)是允许Xcode扫描您的代码,并找到这些点,您的控制器需要通过IB连接到视图。如果您以编程方式将控件连接到该方法,则不需要声明的 IBAction 部分。

The word IBAction itself is #defined as void. Its only purpose (and the same is true of IBOutlet) is to allow Xcode to scan your code and find these points where your controller needs to be wired up views via IB. You don't need the IBAction part of the declaration if you're programmatically connecting a control to that method.

没有性能差异,但在语义上,在你的实现文件中放置一个 IBAction 没有什么意义。有一个 IBAction 意味着控制器通过该方法与外部对象通信,这正是头/ public @interface 声明为

There's no performance difference, but semantically, putting an IBAction in your implementation file doesn't really make sense. Having an IBAction means the controller is communicating to an outside object via that method, and that's exactly what header/public @interface declarations are for.

这篇关于我应该把IBActions在头文件或不是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆