動的ページを含むアプリケーションを作成しています。実際、サーバーからの応答をチェックして、いくつかの動的な質問と UIButton (カスタム チェックボックス) を作成しました。私のコードはここにあります、
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に変更する必要がある場合、ボタンのアクションでは機能しません。ボタンのグループから動的に作成されたボタンのコントロールにアクセスするにはどうすればよいですか?
私の要件を理解していただけると思います。よろしくお願いします。