Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView - reusing cells while in editing mode

I'm finding that if you set a table view into editing mode, upon scrolling the table after deleting a row the cell edit control (the red minus sign on the left) is in a random state (turned vertical or horizontal) on the rest of the cells as you scroll the table. Presumably because I'm reusing cells like this:

cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

How can I force the edit control to be in the correct state for each cell? It should always be in the default horizontal state unless I tap it to delete a cell.

EDIT: Here's the cell code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"WhateverIdentifier";
    MyCell *cell = nil;

    //This IF statement fixes the problem, but then I'm not reusing the cells
    if (!tableView.isEditing) {
        cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    }

    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:self options:nil] objectAtIndex:0];

    }

    //customize cell

    return cell;
}
like image 808
soleil Avatar asked Mar 23 '23 12:03

soleil


1 Answers

Are you calling [super prepareForReuse] in the method prepareForReuse of your custom cell?

That resolved my problem.

like image 181
Nuno Vinhas Avatar answered Apr 26 '23 04:04

Nuno Vinhas