xcode 4.5 中XIB文件中IBOutlet如何关联控件

来源:互联网 发布:java list导出csv 编辑:程序博客网 时间:2024/05/21 14:05

今天下午为这个耽误了一两个小时,以前用低版本3.2,IBOutlet和IBAction都可以添加在IBuilder中,4.5 找不到添加的地方。

正确的关联,遵循以下几个步骤:

1 在A.h头文件中 声明属性 

@property (strong, nonatomic) IBOutlet UILabel *lblStationName;


2 打开A.xib文件,在Identity Inspector中,Custom Class 选择A,而不是默认的TableViewCell

3 在A.xib 中添加一个 Label控件

4 在Connections Inspector中,就会出现lblStationName,点中后面的+号,拖动到Label控件,

使之关联,关联成功 Label控件会变成蓝色。

 

今天又发现另外一种关联方法,分享给大家。

情景描述:随便新建了一个viewController,取名A,在里面拖了一个Button,想给Button加一个Click事件。

1

A.h

@interface A: UIViewController

@property (strong,nonatomic) IBOutlet UIButton * viewButton;

-(IBAction) viewButtonClick:(id) sender;

@end;

2 在A.xib中操作

 选中添加的按钮,在Connections Inspector中,Sent Events中,按住Ctrl键,和Touch Down 后面对应的+,拖动到File's Owner,就会出现IBAction viewButtonClick,点击就关联上了。

 

原创粉丝点击