我关注评论并尝试解决我的问题,但仍然无法正常工作。
当我在模拟器上运行测试演示时,我得到了这个:
我点击了test2,我想在清除按钮标题之前更改按钮标题,但我
得到这个 :
单击另一个按钮时,我无法清除按钮标题。
任何人都可以帮忙??
这是我的代码
-(void)addbutton
{
for (int i=0; i<3; i++)
{
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake((i*100), 0, 100, 100)];
button.titleLabel.text = @"";
[button setTag:i];
[button setTitle:[self.demoDataArray objectAtIndex:i] forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
button.backgroundColor = [UIColor clearColor];
[button addTarget:self action:@selector(setButtonTitle:) forControlEvents:UIControlEventTouchUpInside];
[self.demoView addSubview:button];
}
}
-(IBAction)setButtonTitle:(id)sender
{
if ([sender tag] == 0)
{
self.demoDataArray = [[NSArray alloc] initWithObjects:@"test5", @"test6", @"test7", @"test8", nil];
[self addbutton];
}
else if([sender tag] == 1)
{
self.demoDataArray = [[NSArray alloc] initWithObjects:@"test9", @"test10", @"test11", @"test12", nil];
[self addbutton];
}
else if([sender tag] == 3)
{
self.demoDataArray = [[NSArray alloc]initWithObjects:@"test13", @"test14", @"test15", @"test16", nil];
[self addbutton];
}
}