Вы не можете просто сделать это с помощью простого UIButton
, так как вам нужно будет определить, какой флажок номера строки был нажат. Следовательно, вместо использования UIButton
непосредственно используйте CustomButton
, который расширяет UIButton и имеет дополнительное свойство rowTag
, например:
@interface CustomButton : UIButton {
NSInteger rowTag;
}
@property NSInteger rowTag;
@end
@implementation CustomButton
@synthesize rowTag;
@end
Сейчас в cellForRowAtIndexPath
:
if(cell==nil){
CustomButton * checkBox=[CustomButton buttonWithType:UIButtonTypeCustom];
checkBox.tag=21;
checkBox.frame=CGRectMake(270,15, 20, 20);
[cell.contentView addSubview:checkBox];
[checkBox addTarget:self action:@selector(checkBoxClicked:) forControlEvents:UIControlEventTouchUpInside];
}
CustomButton *btn = [cell.contentView viewWithTag:21];
[btn setRowTag:indexPath.row];
if(selectedProperty){
[checkBox setImage:[UIImage imageNamed:@"selectedBoxWithTik.png"] forState:UIControlStateNormal];
}
else
[checkBox setImage:[UIImage imageNamed:@"selectedBoxWith.png"] forState:UIControlStateNormal];
Надеюсь, это поможет.