我有一组按钮,我想在单击时显示按钮标题并在再次单击时隐藏。这是我的代码,
- (IBAction)buttonAction:(id)sender
{
UIButton *button = (UIButton *)sender;
int index = button.tag;
[temp replaceObjectAtIndex:index withObject:@"1"];
[self showing];
}
-(void)showing
{
UIButton *button = nil;
NSString *name = nil;
int i = 0;
for(UIView *view in self.view.subviews)
{
if([view isKindOfClass:[UIButton class]])
{
button= (UIButton *)view;
if(button.tag >= 1 && button.tag <= 16)
{
name = [NSString stringWithFormat:@"%@",[texts objectAtIndex:i]];
if ([[temp objectAtIndex:i] isEqualToString:@"1"])
{
[button setTitle:name forState:UIControlStateNormal];
NSLog(@"current name :%@",name);
}
else
{
[button setTitle:@"" forState:UIControlStateNormal];
}
i++;
}
}
}
}
但它会在第一次单击时显示整个按钮标题,我只想显示单击的按钮标题。请帮助我应该对我的代码进行哪些更改?