I currently have 14 buttons that are created programmatically using a for loop, the code below:
int buttonCount = 14;
for (int i=0; i< buttonCount; i++) {
NSString *stringFromInt = [NSString stringWithFormat:@"%@",[arrayForRound objectAtIndex:i]];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self
action:@selector(buttonSelected:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:stringFromInt forState:UIControlStateNormal];
button.titleLabel.font = [UIFont fontWithName:@"helvetica" size:19];
button.tag = i;
[self.view addSubview:button];
}
This works great for creating buttons, after which I can fill out the answer block with the value of the selected button:
-(void)buttonSelected: (UIButton *)sender
{
[_buttonOne setTitle:sender.titleLabel.text forState:UIControlStateNormal];
}
However, after the button was full, I would like to remove it from the screen. If I call button.hidden, it just hides the last button that was programmed by the program. I know button.tag and try to use this, but it seems to me that I almost need to do something like:
//Hide button for tag (i know this is incorrect syntax)
button for buttonTag: 3 setHidden;
Is there something similar or a way to do this?
Update
, , , . , _buttonOne create ( letterButton), Button ,
UIButton *yourBtn = (UIButton *)[self.button viewWithTag:3];
[yourBtn setHidden:YES];
(code posted by Oh Seung Kwon)
, . ( _buttonOne, letterButton).
, 12 nib ... 12.