【发布时间】:2012-05-17 14:41:44
【问题描述】:
我正在以编程方式创建UIButtons,然后将这些UIButtons 存储在NSMutableArray 中。所有这些UIButtons 都有一些文本作为标题。我没有这些UIButtons 的出口。现在我想在触摸或单击某些UIButton 时将UIButton 的标题分配给UIlabel。但对我来说问题是:我怎样才能在这些UIButtons 上执行该功能。因为我以编程方式创建了UIButtons,而且这些UIButtons 没有插座。这是我创建按钮的代码:
saveBtn = [[NSMutableArray alloc] init];
for (int i=0; i<30; i++) {
if (btnn>8) {
UIButton *btn = [UIButton
buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(200.0 , spacey, 30.0, 30.0);
int idx;
idx = arc4random()%[arr count];
NSString* titre1 = [arr objectAtIndex:idx];
[btn setTitle:titre1 forState:UIControlStateNormal];
spacey=spacey+30;
spacex = 80;
btnn = 0;
}
else {
btnn++ ;
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(spacex, spacey, 30.0, 30.0);
int idx;
idx = arc4random()%[arr count];
NSString* titre1 = [arr objectAtIndex:idx];
[btn setTitle:titre1 forState:UIControlStateNormal];
spacex = spacex + 30;
[saveBtn addObject:btn];
[self.view addSubview:btn];
}
}
请任何人都可以指导我如何为这些NSMutableArray UIButtons 执行操作。
【问题讨论】:
标签: iphone objective-c ios uibutton nsmutablearray