2011-12-13 50 views
1

我尝试做这样的值:变量名的INT I

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

其中UIButton *btn_ii​​价值。

有可能在的OBJ-C?

+0

你不会得到太多milage这些计算`0 * numberRowsOfMenu,0 * heightOfRow` – 2011-12-13 18:22:24

+0

我知道,这不是完整的参数:)的 – 2011-12-13 18:23:51

回答

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];