我已经创建了表。在每个单元格上,我根据标志数组中的值添加按钮。这是我在单元格上添加按钮的代码
if ([[self.flags objectAtIndex:indexPath.row]
isEqualToString:@"false"])
{
UIButton *btnFlag = [UIButton buttonWithType:UIButtonTypeCustom];
[btnFlag addTarget:self
action:@selector(flagButtonPressed:)
forControlEvents:UIControlEventTouchDown];
btnFlag.backgroundColor = [UIColor redColor];
[btnFlag setTitle:@"flag" forState:UIControlStateNormal];
btnFlag.frame = CGRectMake(230, 40, 50, 20);
[cell addSubview:btnFlag];
}else if ([[self.flags objectAtIndex:indexPath.row] isEqualToString:@"true"])
{
UIButton *btnFlag = [UIButton buttonWithType:UIButtonTypeCustom];
[btnFlag setHidden:YES];
[cell addSubview:btnFlag];
}
-(void)flagButtonPressed:(id)sender {
UITableViewCell *owningCell = (UITableViewCell*)[sender superview];
indexPathToCell = [self.cotDetailsTbl indexPathForCell:owningCell];
// some stuff }
在上述方法中,我调用 api 并根据获得的响应将标志数组中的值从 false 替换为 true。一旦标志数组中的值变为真,我将重新加载表。
但问题是当我重新加载表格时,按钮仍然显示它没有隐藏
谢谢