【发布时间】:2010-08-06 08:00:01
【问题描述】:
这是我一直在玩的一些代码;由于某种原因,我无法让它一次创建一个按钮。例如你有; for(i = 1; i
//这里我们把按钮放在屏幕Y轴上的位置 浮动 startPositionY = 70.0;
for(int i = 1; i <= 4; i++) {
NSString *button = [NSString stringWithFormat:@"button%i", i];
// NSMutableString version to keep button from changing name.
//NSString *button = [NSMutableString stringWithFormat:@"button%i", i];
UIButton *tempBName = (UIButton *)[UIButton buttonWithType:UIButtonTypeRoundedRect];
[tempBName setTitle:button forState:UIControlStateNormal];
tempBName.tag = i;
[tempBName addTarget:self action:@selector(clickMe:)forControlEvents:UIControlEventTouchUpInside];
tempBName.frame = CGRectMake(0.0, 0.0, 80.0, 50.0);
tempBName.center = CGPointMake(160.0, 50.0+startPositionY);
tempBName.titleLabel.adjustsFontSizeToFitWidth = TRUE;
[self.view addSubview:tempBName];
// Make space between each button
startPositionY += 70;
// How many buttons out of "i" are we creating?
NSLog(@"%d", i);
// release button
[button release];
}
// Was the button Pressed?
NSLog(@"Did Press");
// Did our Position change on the Y-axis?
NSLog(@"%f", startPositionY);
谢谢,
【问题讨论】:
-
首先,不需要释放
button,没有alloc,new或者copy。那么你看到了什么或没看到什么?
标签: iphone button uibutton iteration