我是 iOS 的新手,我在我的 tableview 中创建动态按钮我已经在按钮上设置了一个图像以进行检查和取消选中我要做的是当我点击(或检查)按钮时,indexpath 行上的数据将添加到我的数组中。如果我取消选择它,数据将从我的数组中删除。请帮我
-(void)btnForCheckBoxClicked:(id)sender
{
UIButton *tappedButton = (UIButton*)sender;
indexForCheckBox= [sender tag];
if([tappedButton.currentImage isEqual:[UIImage imageNamed:@"checkbox_unchecked.png"]])
{
[sender setImage:[UIImage imageNamed: @"checkbox_checked.png"] forState:UIControlStateNormal];
strinForCheckBox= [ApplicationDelegate.ArrayForSearchResults objectAtIndex:indexForCheckBox];
[arrForCheckBox addObject:strinForCheckBox];
NSLog(@"Sender Tag When Add %d", indexForCheckBox);
NSLog(@"Array Count Check Box %d",[arrForCheckBox count]);
}
else
{
[sender setImage:[UIImage imageNamed:@"checkbox_unchecked.png"]forState:UIControlStateNormal];
[arrForCheckBox removeObjectAtIndex:indexForCheckBox];
NSLog(@"Sender Tag After Remove %d", indexForCheckBox);
NSLog(@"Array Count Uncheck Box %d",[arrForCheckBox count]);
}
}