- 浏览: 44172 次
- 性别:
- 来自: 河南
最新评论
If you go into the UIKit_Framework and look at the NSNibDeclarations.h header file, you’ll see that they’re defined like this: macros(宏)
#define IBAction void
#define IBOutlet
#define IBOutletCollection(ClassName)
Confused? These two keywords do absolutely nothing as far as the compiler is concerned. IBOutlet gets entirely removed from the code before the compiler ever sees it. IBAction resolves to a void return type, which just means that action methods do not return a value. So, what’s going on here?
The answer is simple, really: IBOutlet and IBAction are not used by the compiler. They are used by Interface Builder. Interface Builder uses these keywords to parse out the outlets and actions available to it. Interface Builder can only see methods that are prefaced with IBAction and can only see variables or properties that are prefaced with IBOutlet. Also, the presence of these keywords tells other programmers, looking at your code in the future, that the variables and methods in question aren’t dealt with entirely in code. They’ll need to delve into the relevant nib file to see how things are hooked up and used.
这两个宏在UIKit_Framework 中定义
IBAction(行为)和IBOutlet(插座)只是告诉InterfaceBuilder这些是用于界面交互的,打开InterfaceBuilder后,首先扫描IBAction和IBOutlet,InterfaceBuilder只识别以IBAction开头的方法和以IBOutlet开头的属性,代码别编译后,IBAction被解析为void,而IBOutlet被解析为空。
http://eyecm.com/iboutlet-and-ibaction-that/
内存管理
如果一个变量在类中被定义为了 IBOutlet 那么你无需对其进行实例化,xib载入器会对其初始化。切记不要初始化两回,内存会溢出,而且对象锁定也会出错。
如果一个变量在类中被定义为了 IBOutlet 那么你必须负责将其释放。xib载入器不会帮忙的。
需要注意的是,任何一个被声明为IBOutlet并且在Interface Builder里被连接到一个UI组件的成员变量,会被额外retain一次。
常见的情形如: IBOutlet UILabel *label;
-(IBAction) btnClicked:(id)sender;
这个label在Interface Builder里被连接到一个UILabel。此时,这个label的retainCount为2。
所以,只要使用了IBOutlet变量,一定需要在dealloc或者viewDidUnload里release这个变量。
实现m文件中:
-(void) dealloc
{
[label release];
[super dealloc];
}
http://blog.joycode.com/ghj/archives/2012/05/22/116258.joy
#define IBAction void
#define IBOutlet
#define IBOutletCollection(ClassName)
Confused? These two keywords do absolutely nothing as far as the compiler is concerned. IBOutlet gets entirely removed from the code before the compiler ever sees it. IBAction resolves to a void return type, which just means that action methods do not return a value. So, what’s going on here?
The answer is simple, really: IBOutlet and IBAction are not used by the compiler. They are used by Interface Builder. Interface Builder uses these keywords to parse out the outlets and actions available to it. Interface Builder can only see methods that are prefaced with IBAction and can only see variables or properties that are prefaced with IBOutlet. Also, the presence of these keywords tells other programmers, looking at your code in the future, that the variables and methods in question aren’t dealt with entirely in code. They’ll need to delve into the relevant nib file to see how things are hooked up and used.
这两个宏在UIKit_Framework 中定义
IBAction(行为)和IBOutlet(插座)只是告诉InterfaceBuilder这些是用于界面交互的,打开InterfaceBuilder后,首先扫描IBAction和IBOutlet,InterfaceBuilder只识别以IBAction开头的方法和以IBOutlet开头的属性,代码别编译后,IBAction被解析为void,而IBOutlet被解析为空。
http://eyecm.com/iboutlet-and-ibaction-that/
内存管理
如果一个变量在类中被定义为了 IBOutlet 那么你无需对其进行实例化,xib载入器会对其初始化。切记不要初始化两回,内存会溢出,而且对象锁定也会出错。
如果一个变量在类中被定义为了 IBOutlet 那么你必须负责将其释放。xib载入器不会帮忙的。
需要注意的是,任何一个被声明为IBOutlet并且在Interface Builder里被连接到一个UI组件的成员变量,会被额外retain一次。
常见的情形如: IBOutlet UILabel *label;
-(IBAction) btnClicked:(id)sender;
这个label在Interface Builder里被连接到一个UILabel。此时,这个label的retainCount为2。
所以,只要使用了IBOutlet变量,一定需要在dealloc或者viewDidUnload里release这个变量。
实现m文件中:
-(void) dealloc
{
[label release];
[super dealloc];
}
http://blog.joycode.com/ghj/archives/2012/05/22/116258.joy
发表评论
-
在真机上运行一个程序的过程以及将app发布到Appstore上的过程
2014-09-05 18:19 645在真机上运行一个程序的过程 1.打开钥匙串 ,从证书颁发 ... -
彻底删除iOS应用,包括沙盒及开发者里边的东西
2014-05-08 16:06 11341.长按图标,出现X号删除 2.clean build f ... -
播放视频
2014-05-05 21:16 638播放视频方法一: MPMoviePlayerContro ... -
播放视频
2014-05-05 21:15 0播放视频方法一: MPMoviePlayerControl ... -
播放视频
2014-05-05 21:13 0播放视频方法一: MPMoviePlayerControl ... -
流式布局界面
2014-03-04 12:49 543想让图标按流式布局,更改控件的Autosizing属性 ... -
iOS流式布局
2014-02-22 14:01 1380想让图标按流式布局,更改控件的Autosizing属性:四周 ... -
Mac OS在线升级以及Xcode升级
2013-12-24 14:02 14257升级苹果系统: 打开AppStore,在搜索栏内输 ... -
instancetype id
2013-12-16 12:27 647Objective-C is a rapidly evolv ... -
@ at
2013-11-21 13:54 647Interface & Implementation ... -
NSPredicate
2013-11-21 10:27 797NSPredicate is a Foundation ... -
NSFileManager
2013-11-21 09:30 575NSFileManager is Foundation's ... -
点击Run按钮后Stop按钮变灰
2013-09-24 17:31 717当把应用程序从模拟器删除(长按AppIcon,图标晃动,出现 ... -
屏幕是横向的时候,NavigationBar总是在下边?
2013-08-20 10:32 685这是由于旋转时没有定位屏幕的位置,我们可以写一个旋转时的方 ... -
Why can't I save data to my application's bundle when running on the device?
2013-08-06 21:19 562Q: My application saves data ... -
Xcode 4.1~4.6 + iOS 5、iOS 6免证书(iDP)开发+真机调试+生成IPA全攻略
2013-07-30 11:33 1145开发环境使用的是目前为止最新的稳定版软件:Mac OS ... -
Which SQLite administration console do you recommend?
2013-07-21 19:30 876I've been on a search for a ...
相关推荐
在iPhone平台上,引入了IBOutlet与IBAction。通过在变量前增加IBOutlet 来说明该变量将与界面上的某个UI对象对应,在方法前增加IBAction来说明该方法将与界面上的事件对应. 下面通过一个连接网络服务器(Network...
做iOS的二维码扫描,有两个第三方库可以选择,ZBar和ZXing。今天要介绍的是iOS7.0后...IBOutlet、IBAction如下: @property (weak, nonatomic) IBOutlet UIView *viewPreview; @property (weak, nonatomic) IBOutlet
4、IBOutlet、IBAction是啥玩意,总能看到。 这两个东西其实在语法中没有太大的作用。如果你希望在Interface Builder中能看 ,NO是0,BOOL本身就是个char。 4、IBOutlet、IBAction是啥玩意,总能看到。 这两...
无拖拽关键点(演示文稿)传统的iOS开发问题@IBOutlet @IBAction链接不编译时间安全笔尖/ XIB / Storyboard合并冲突。 100%的时间不保证安全故事板prepareForSegue loadNib打破了OOP。 Views或ViewController始终...
@property (weak, nonatomic) IBOutlet UILabel *indexLabel; // 图像数据 @property (nonatomic, strong) NSArray *imageArray; // 图像控件 @property (weak, nonatomic) IBOutlet UIImageView *imageView; // ...
@interface ViewController () ...@property (nonatomic, weak) IBOutlet UIButton *head; // 移动 - (IBAction)move:(UIButton *)btn; // 放大 - (IBAction)big; // 缩小 - (IBAction)small; @end
4.#import作用如同#include,用于声明头文件。 5.nil表示空指针,相当于java的null 6.objc中使用字符串,前面要加上"@",是因为在前面加上"符号",编译器在编译的时候会在程序中给你留出位置,这样才能保证这个字符...
@property (weak, nonatomic) IBOutlet UITextField *qqField; @property (weak, nonatomic) IBOutlet UITextField *pwdField; - (IBAction)login; @end @implementation ViewController - (IBAction)login { ...
使用IBAction和IBOutlet在Interface Builder文件和代码之间创建链接。 熟悉Xcode代码编辑器。 学习使用注释来注释代码。 了解并使用Swift常量和变量。 了解和使用集合类型,例如Swift数组。 使用Xcode控制台...
使用IBAction和IBOutlet在Interface Builder文件和代码之间创建链接。 熟悉Xcode代码编辑器。 学习使用注释来注释代码。 了解并使用Swift常量和变量。 了解和使用集合类型,例如Swift数组。 使用Xcode控制台...
使用IBAction和IBOutlet在Interface Builder文件和代码之间创建链接。 熟悉Xcode代码编辑器。 学习使用注释来注释代码。 了解并使用Swift常量和变量。 了解和使用集合类型,例如Swift数组。 使用Xcode控制台...
使用IBAction和IBOutlet在Interface Builder文件和代码之间创建链接。 熟悉Xcode代码编辑器。 学习使用注释来注释代码。 了解并使用Swift常量和变量。 了解和使用集合类型,例如Swift数组。 使用Xcode控制台测试和...
使用IBAction和IBOutlet在Interface Builder文件和代码之间创建链接。 熟悉Xcode代码编辑器。 学习使用注释来注释代码。 了解并使用Swift常量和变量。 了解和使用集合类型,例如Swift数组。 使用Xcode控制台...
使用IBAction和IBOutlet在Interface Builder文件和代码之间创建链接。 熟悉Xcode代码编辑器。 学习使用注释来注释代码。 了解并使用Swift常量和变量。 了解和使用集合类型,例如Swift数组。 使用Xcode控制台测试和...
使用IBAction和IBOutlet在Interface Builder文件和代码之间创建链接。 熟悉Xcode代码编辑器。 学习使用注释来注释代码。 了解并使用Swift常量和变量。 了解和使用集合类型,例如Swift数组。 使用Xcode控制台测试和...
使用IBAction和IBOutlet在Interface Builder文件和代码之间创建链接。 熟悉Xcode代码编辑器。 学习使用注释来注释代码。 了解并使用Swift常量和变量。 了解和使用集合类型,例如Swift数组。 使用Xcode控制台测试和...
多余的连线没有删除(创建了多余的IBAction) reason: '[<ViewController> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key label1.' 多余的连线没有删除(创建了多余的...
14.5.2 使用ibaction200 14.6 其他动作功能201 14.6.1 uitextfield201 14.6.2 uislider203 14.6.3 textfield/slider组合203 14.6.4 创建动作很容易204 14.6.5 使用动作204 14.7 通知简介204 14.8 小结205 ...
查找常见的xib和情节提要相关问题,而无需运行您的应用程序或编写单元测试。 用法 将项目的路径传递到ibanalyzer命令行工具。 这是您可以预期的示例输出: $ ./ibanalyzer ~/code/Sample/ TwitterViewController ...