あなたはこれを行うことができます -
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
if (cell == nil)
{
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
if([[[Usercontacts objectAtIndex:indexPath.row]objectForKey:@"isChecked"]isEqualToString:@"NO"])
{
[checkUncheckBtn setImage:[UIImage imageNamed:@"unchecked box.png" ]forState:UIControlStateNormal];
checkUncheckBtn.tag=1;
}
else
{
[checkUncheckBtn setImage:[UIImage imageNamed:@"checked box.png" ]forState:UIControlStateNormal];
checkUncheckBtn.tag=2;
}
[checkUncheckBtn addTarget:self action:@selector(checkUncheckBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
実行するとcheckUncheckBtnPressed
:メソッドは次のようになります
-(void)checkUncheckBtnPressed:(id)sender
{
UIButton *btn=(UIButton*)sender;
UITableViewCell *cell =(UITableViewCell *) [sender superview] ;
NSIndexPath *_indxpath = [createGroupContactsTableView indexPathForCell:cell];
if(btn.tag==1)
{
[btn setImage:[UIImage imageNamed:@"checked box.png" ]forState:UIControlStateNormal];
btn.tag=2;
[[Usercontacts objectAtIndex:_indxpath.row]setObject:@"YES" forKey:@"isChecked"];
}
else
{
[btn setImage:[UIImage imageNamed:@"unchecked box.png" ]forState:UIControlStateNormal];
btn.tag=1;
[[Usercontacts objectAtIndex:_indxpath.row]setObject:@"NO" forKey:@"isChecked"];
}
}