1

i try made something like this:

for (int i=0; i<8; i++) {
    UIButton *btn_i = [[UIButton alloc] initWithFrame:CGRectMake(0 * numberRowsOfMenu, 0 * heightOfRow, btnWidth, btnHeight)];
}

where UIButton *btn_i is btn_ + value of i.

it is possible in Obj-C?

Tomasz Szulc
  • 4,217
  • 4
  • 43
  • 79

1 Answers1

4

Do you mean you want to wind up with variables with names like btn_0, btn_1, etc?

No, you cannot do this. You might be better off with something like this:

NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:8];
for(int i=0; i<8; i++) {
    UIButton *b  = [[UIButton alloc] initWithFrame:...];
    [butttons addObject:b];
    [b release];
}

// Now you can access the buttons array with indices, e.g:
UIButton *b = [buttons objectAtIndex:4];
Mark Granoff
  • 16,878
  • 2
  • 59
  • 61