4
votes

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;
}
2
Can you post more details about your code? - gsach
Posted an update to the question. - soleil
Does the MyCell* class have any custom things? - gsach
An image and a text label. - soleil
Any solution? I'm seeing the same thing in two separate projects - garafajon

2 Answers

7
votes

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

That resolved my problem.

0
votes

I just checked in a UITableView I had handy, and I don't see that problem. I'm using dequeueReusableCellWithIdentifier: as you are (without the if statement, of course). Are you doing something special with swiping, or deleting multiple rows or something?

(I'd make this a comment but can't yet. I'll delete it once you've resolved your problem.)