我有一个带有 3 个 UIButtons 的 NSMutableArray 和一个带有 50 个 UIButtons 的第二个 NSMutableArray。我想将这 3 个 UIButton 标题逐个字符地分配给 SecondArray 的每个 UIButton。但是 Second Array 的这 50 个 UIButton 中的每一个都已经有一个 Character。我的基本目的是首先我想检查每个 UIButton 的长度我的第一个数组的 uibutton 标题,然后将其按索引分配给第二个数组中的 UIButton。(对于 Exp,如果我的第一个按钮有标题“堆栈”,第二个“结束”和第三个“流”不我想分配索引的 UIButtons 0-5 ,13-16,35-38 在第二个数组中)。我的第一个数组有 3 个 UIBttons 。这里是代码。
NSMutableArray *buttons = [NSMutableArray arrayWithObjects:btn1, btn2, btn3, nil];
[btn1 setTitle:@"stack" forState:UIControlStateNormal];
[btn2 setTitle:@"over" forState:UIControlStateNormal];
[btn3 setTitle:@"flow" forState:UIControlStateNormal];
这是我的代码。创建 50 个 UIButton。
-(void)button:(id)sender {
saveBtn = [[NSMutableArray alloc] init];
arr=[[NSArray alloc]
initWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",
@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z",nil];
for (int i=0; i<50; i++) {
btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(spacex, spacey, 30.0, 30.0);
int idx;
idx = arc4random()%[arr count];
NSString* titre = [arr objectAtIndex:idx];
[btn setTitle:titre forState:UIControlStateNormal];
spacex = spacex + 30;
[saveBtn addObject:btn];
[self.view addSubview:btn];
}
}
任何人都指导我如何将我的 UIButton 标题分配给特定索引上的这些 UIButton。谢谢