xcode IB在IBAction、IBOutlet等中是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8592056/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:48:05  来源:igfitidea点击:

What does IB mean in IBAction, IBOutlet, etc..?

iphonexcode

提问by Aldee

I am very new to iPhone development. I often encounter IBAction, IBOutletand so on when reading Objective-C and Swift code. What does IBstand for?

我对 iPhone 开发很陌生。我在阅读 Objective-C 和 Swift 代码时经常会遇到IBAction,IBOutlet等等。代表什么IB

回答by sidyll

"Interface Builder".

“界面生成器”。

Before Xcode 4, the interface files (XIBs and NIBs) were edited in a separate program called Interface Builder, hence the prefix.

在 Xcode 4 之前,接口文件(XIB 和 NIB)是在一个名为 Interface Builder 的单独程序中编辑的,因此是前缀。

IBActionis defined to void, and IBOutletto nothing. They are just clues to Interface Builder when parsing files to make them available for connections.

IBAction被定义为void,并且IBOutlet什么都没有。在解析文件以使其可用于连接时,它们只是 Interface Builder 的线索。

Just to add the reference, inside AppKit/NSNibDeclarations.h you'll find these:

只是为了添加引用,在 AppKit/NSNibDeclarations.h 中你会发现这些:

#ifndef IBOutlet
#define IBOutlet
#endif

#ifndef IBAction
#define IBAction void
#endif

So, actually, code like this:

所以,实际上,代码是这样的:

@interface ...
{
    IBOutlet NSTextField *label;
}
- (IBAction)buttonPressed:(id)sender;
@end

Will be transformed into:

将转化为:

@interface ...
{
     NSTextField *label;
}
- (void)buttonPressed:(id)sender;
@end

By the preprocessor, even before the compiler sees it. Those keywords were acting just as clues to Interface Builder.

通过预处理器,甚至在编译器看到它之前。这些关键字充当了 Interface Builder 的线索。

回答by Ankit Srivastava

IB stands for interface builder, as you connect objects via the interface builder .

IB 代表接口构建器,因为您通过接口构建器连接对象。

回答by satisharyan

IBAction and IBOutlet are interface Builder Constants IBOutlet:A Controller class can refer to the object in the nib file using a special constant called IBOutlet.

IBAction 和 IBOutlet 是接口 Builder 常量 IBOutlet:Controller 类可以使用称为 IBOutlet 的特殊常量来引用 nib 文件中的对象。

IBActions:Interface objects in the nib file can be set to trigger specific methods in controller class using IBAction as return type of the method.

IBActions:nib 文件中的接口对象可以设置为触发控制器类中的特定方法,使用 IBAction 作为方法的返回类型。