Armanoide
Armanoide

Reputation: 1348

UIButton of UITableViewCell disappear on scroll

I Have a problem with my custom UItableViewCell. It's seems that all UIButton of UITableViewCell disappear on scroll. Specilay on my 25 cell. Any one have any idea ?

any help would be appreciated :)

enter image description here

That some code :

- (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;
}

Upvotes: 0

Views: 655

Answers (2)

Armanoide
Armanoide

Reputation: 1348

I solve my problem. The problem is that i was using Tag for my UIButton and the identifier was the same number tag of another UIView so when i was removing my UIView the UIButton disappear also. Thanks all for your answer.

Upvotes: 1

Kaveh Vejdani
Kaveh Vejdani

Reputation: 224

Remove if (!cell)

And you're good to go.

Upvotes: 0

Related Questions