我正在创建一个包含动态页面的应用程序。实际上,我通过检查来自服务器的响应创建了一些动态问题和 UIButtons(自定义复选框)。我的代码在这里,
NSString *response=[ResponseFromServer ObjectAtIndex:0];
if ([comSt compare: @"CheckBoxList"]==NSOrderedSame)
{
int count=[ResponseFromServer count];
for(int i=0;i<count;i++)
{
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.tag=i;
[button setFrame:CGRectMake(0.0f, 0.0f, 37, 37)];
[button setCenter:CGPointMake(116.0,p1)];
[button setImage:[UIImage imageNamed:@"uncheck.png"] forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor whiteColor]];
[button addTarget:self action:@selector(checkButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[self.scrollView addSubview:button];
p1=p1+30;
}
-(void)checkButtonTapped:(id)sender
{
int tagVal = [(UIButton*)sender tag];
if (tagVal==0) {
NSLog(@"tag = 0");
[button setSelected:YES];
[button setImage:[UIImage imageNamed:@"check.png" forState:UIControlStateSelected]; //not working, button image is not changing
}
假设我创建了 5 个具有不同标签的动态按钮。我首先将所有这些按钮的图像设置为 uncheck.png。有用。但是当我单击特定按钮并需要将该按钮图像更改为checked.png时,它无法处理按钮操作。我需要像复选框控件一样更改它,我将如何从一组按钮访问动态创建的按钮的控件?
我想你可以理解我的要求,提前谢谢..