把随机的UIButtons标题的NSMutableArray NSMutablearray的UIButtons

我有一个NSMutableArray 3 UIButtons和第二个NSMutableArray 50 UIButtons。 我想把这3个UIButtons标题按字符分配给每个UIButton的SecondArray.but这50个UIButtons中的每一个都有单一的Character.My Basics的目的是,首先我想检查每个的长度我的第一个数组的uibutton标题,然后将其分配给第二个数组中的UIButton索引(如果我的第一个button有标题“堆栈”,第二个“超过”和第三个“stream”no我要分配指数的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]; 

这是我的代码。创build50个UIButtons。

  -(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标题到特定索引上的这些UIButtons。 感谢名单

感谢帮助每一个..但我做了这里是code.my是帮助别人。

  - (void)getbuttontitle { for(int i = 0;i<[buttons count];i++) { if(i == 0) { UIButton *b1 = [buttons objectAtIndex:0]; a = (NSString *)[[b1 titleLabel] text]; [storewords addObject:a]; NSLog(@"b=%@",a); } else if(i == 1) { } else if(i == 2) { } } } for (NSString *str in storewords) { if (str==a) { int j = 0; int randn= (arc4random()%5)+1 ; NSLog(@"n=%d",randn); for (int i=randn; i<[a length]+randn; i++) { NSLog(@"a=%@",a); NSString *ichar = [NSString stringWithFormat:@"%c", [a characterAtIndex:j]]; UIButton* b = [saveBtn objectAtIndex:i]; NSLog(@"a=%@",ichar); j++; [b setTitle:ichar forState:UIControlStateNormal]; } } if (str==c) { } if (str==d) { } }