我尝试做这样的事情:
for (int i=0; i<8; i++) {
UIButton *btn_i = [[UIButton alloc] initWithFrame:CGRectMake(0 * numberRowsOfMenu, 0 * heightOfRow, btnWidth, btnHeight)];
}
其中UIButton *btn_i
为btn_
+ i
的值。
有可能在Obj-C?
答案 0 :(得分: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];