IBOutletCollection (UIbutton) [英] IBOutletCollection (UIbutton)

查看:28
本文介绍了IBOutletCollection (UIbutton)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 .h 中

IBOutlet NSMutableArray *buttons;
@property (nonatomic, retain) IBOutletCollection(UIButton) NSMutableArray *buttons;
-(void)play:(UIButton *)theButton;

在我的 .m 我有

-(void)initButtons{
buttons = [[NSMutableArray alloc] initWithCapacity:1];
UIButton *myBut = [UIButton alloc];
[buttons addObject: myBut];
[[buttons objectAtIndex:0] addtarget:self action@selector(play:) forControlEventTouchUpInside];
}

...

-(void)dealloc{
[buttons dealloc];
[super deallloc];
}

.....

-(void)viewDidLoad{
[super viewDidLoad];
[self initButtons];
}

我将界面构建器中的按钮 IBoutletCollection 拖到一个简单的按钮上,但是当我测试它时它没有执行预期的操作;

I dragged the buttons IBoutletCollection in interface builder to a simple button, but when I test it it doesn't perform the expected action;

我应该提到的是,如果我将我的操作转换为 (IBAction) 而不是 (void) 并将其链接到它起作用的按钮;

I should mention that if I turn my action into (IBAction) instead of (void) and link it to the button it works;

我不太了解 NSArrays 和 outlet 集合.

I don't understand very well NSArrays and outlet collections.

推荐答案

使用您连接到 NIB 中的集合的任何按钮为您设置数组.它无法执行任何操作,因为您已在此处重置 ivar:

The array is set for you with whatever buttons you've connected to the collection in the NIB. It fails to do anything because you've reset the ivar here:

buttons = [[NSMutableArray alloc] initWithCapacity:1];

...或者因为您没有将按钮连接到集合.

…or because you've not connected buttons to the collection.

这篇关于IBOutletCollection (UIbutton)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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