1

私はこのようなものを作ってみました:

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

ここでUIButton *btn_ibtn_+ の値ですi

Obj-Cで可能ですか?

4

1 に答える 1

4

btn_0、btn_1 などの名前の変数を使用したいということですか?

いいえ、できません。次のような方が良いかもしれません:

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];
于 2011-12-13T18:16:33.853 に答える