UITableViewCell的UIButton在滚动时消失

时间:2014-04-23 15:04:10

标签: uitableview uiview uiscrollview uibutton

我的自定义UItableViewCell有问题。似乎滚动UIButton 的所有UITableViewCell消失。我25细胞上的特异性。有人有任何想法吗?

任何帮助将不胜感激:)

enter image description here

有些代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString*  cellIdentifier = @"Cell";

    Cell * __strong cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];


    if (!cell){
        cell = [[Cell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }

    InfoObject __weak *obj = [_pos objectAtIndex:indexPath.row];


    [cell configCell];

    cell.id = obj.id;

    {// EVENT ON BUTTON
        [cell.checkbox addTarget:self action:@selector(checkup:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btnPaymentState addTarget:self action:@selector(changePaymentState:) forControlEvents:UIControlEventTouchUpInside];
    }


    {// SET BUTTON CHECKBOX
        cell.checkbox.tag = indexPath.row;
        [cell.checkbox setImage:[UIImage imageNamed:IMG_BLACK_UNCHECKBOX] forState:UIControlStateNormal];
        [cell.checkbox setImage:[UIImage imageNamed:IMG_BLACK_CHECKBOX] forState:UIControlStateSelected];
        [cell.checkbox setImage:[UIImage imageNamed:IMG_BLACK_CHECKBOX] forState:UIControlStateHighlighted];
    }

    {// SET BUTTON PAYMENT STATE
        cell.btnPaymentState.tag = indexPath.row;
        [cell.btnPaymentState setImage:[self getImageAssociateWithName:obj.stringPaymentState] forState:UIControlStateNormal];
        [cell.btnPaymentState setImage:[self getImageAssociateWithName:obj.stringPaymentState] forState:UIControlStateSelected];
        [cell.btnPaymentState setImage:[self getImageAssociateWithName:obj.stringPaymentState] forState:UIControlStateHighlighted];
    }
    [self SetSelectedBackgroundColorSelectedForFolderCellAtRow:indexPath.row
                                                              :obj.selected Cell: cell];
    [cell.checkbox setSelected:obj.selected];
    [self setCellColorTextOfObjectPrepare:cell withObj:obj];
    return cell;
}

2 个答案:

答案 0 :(得分:1)

我解决了我的问题。问题是我在UIButton使用标记,而identifier相同 数字 标记另一个 UIView 所以当我删除UIView UIButton时,{{1}}也会消失。谢谢大家的回答。

答案 1 :(得分:0)

删除if(!cell)

你很高兴。