UItable单元格中的CheckMark按钮无法正常工作提前谢谢,表格单元格中的CheckMark按钮无法正常工作
self.btn_acceptCheckmark = [[UIButton alloc] initWithFrame:CGRectMake(250 , 25, 20, 20)];
[self.btn_acceptCheckmark setBackgroundImage:[UIImage imageNamed:@"checkmarknormal.png"] forState:UIControlStateNormal];
[self.btn_acceptCheckmark addTarget:self action:@selector(CheckMarkaction:) forControlEvents:UIControlEventTouchUpInside];
[self.btn_acceptCheckmark setBackgroundColor:[UIColor clearColor]];
self.btn_acceptCheckmark.clipsToBounds = YES;
cellforrowattindexpath: 表视图indexpath = 4
else if (indexPath.section == 4){
if (indexPath.row == 0) {
lbl_offerertittle.text = @"Offerers";
[cell addSubview:self.btn_acceptCheckmark];
self.btn_acceptCheckmark.hidden=YES;
}
if ([[offersAsset valueForKey:@"offers"] isEqualToString:@"No listing"]) {
lbl_offererName.text = @"No offers available!";
lbl_offererName.textColor = [UIColor grayColor];
}
else {
self.btn_acceptCheckmark.hidden=NO;
lbl_offererCount.text = @"";
复选标记按钮操作方法
-(IBAction)CheckMarkaction:(id)sender {
if (self.btn_acceptCheckmark.isSelected==YES)
{
[self.btn_acceptCheckmark setBackgroundImage:[UIImage imageNamed:@"checkmarkactive.png"] forState:UIControlStateNormal];
/// self.btn_acceptCheckmark .backgroundColor=[UIColor clearColor];
[self.btn_acceptCheckmark setSelected:NO];
[self.tbl reloadData];
}else if (self.btn_acceptCheckmark.isSelected==NO)
{
[self.btn_acceptCheckmark setBackgroundImage:[UIImage imageNamed:@"checkmarkactive.png"] forState:UIControlStateNormal];
//self.btn_acceptCheckmark .backgroundColor=[UIColor clearColor];
[self.btn_acceptCheckmark setSelected:YES];
[self.tbl reloadData];
}
}
答案 0 :(得分:0)
希望您至少获得了复选标记按钮。您可以使用以下代码在UITableViewCell中切换按钮的图像。它对我有用。对于表格视图单元格,我猜你也必须得到索引路径。
- (void)selectDistance: (UIButton *)button event:(UIEvent *)event{
NSIndexPath* indexPath = [self.table indexPathForRowAtPoint:
[[[event touchesForView:button] anyObject]
locationInView:self.table]];
if (button.selected) {
[button setBackgroundImage:[UIImage imageNamed:@"checkboxoff-5.png"] forState:UIControlStateNormal];
[button setSelected:NO];
}else{
[button setBackgroundImage:[UIImage imageNamed:@"checkboxon-5.png"] forState:UIControlStateNormal];
[button setSelected:YES];
}