我对iPhone开发很新.我经常遇到IBAction,IBOutlet等等,在阅读Objective-C和Swift代码时.什么IB代表什么?
sid*_*yll 57
"界面生成器".
在Xcode 4之前,接口文件(XIB和NIB)在一个名为Interface Builder的独立程序中编辑,因此是前缀.
IBAction被定义为void,并且IBOutlet没有.在解析文件以使其可用于连接时,它们只是Interface Builder的线索.
只是添加引用,在AppKit/NSNibDeclarations.h中你会发现这些:
#ifndef IBOutlet
#define IBOutlet
#endif
#ifndef IBAction
#define IBAction void
#endif
Run Code Online (Sandbox Code Playgroud)
所以,实际上,这样的代码:
@interface ...
{
IBOutlet NSTextField *label;
}
- (IBAction)buttonPressed:(id)sender;
@end
Run Code Online (Sandbox Code Playgroud)
将转化为:
@interface ...
{
NSTextField *label;
}
- (void)buttonPressed:(id)sender;
@end
Run Code Online (Sandbox Code Playgroud)
通过预处理器,甚至在编译器看到它之前.这些关键字就像Interface Builder的线索一样.
| 归档时间: |
|
| 查看次数: |
11075 次 |
| 最近记录: |