Create a for loop to add 39 buttons to an array

前端 未结 5 763
情书的邮戳
情书的邮戳 2021-01-02 11:07

I have 39 different UIButton variables in my .h file, but I would like to add each of them to an array without having to type out the same thing 39 times.

Is there a

5条回答
  •  无人及你
    2021-01-02 11:20

    Like so:

    NSMutableArray *arr = [NSMutableArray array];
    for(int i = 1; i <= 39; ++i) {
      [arr addObject:[self valueForKey:[NSString stringWithFormat:@"btn%d", i]]];
    }
    

提交回复
热议问题