Hello Guys,
Here is some code I have been playing with; for some reason I cannot get it to create a single button at a time. For example you have ; for(i = 1; i <=12; i++) should mean that for each time an external button is pressed a new one is created until 12 buttons have been created. Then there should be a i = 12;break somewhere. However I cannot seem to get this loop to work. Any assistance would be greatly appreciated.
// Where we place the button on the Y-axis on the screen position float 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);
Thanks,