UITableView - reuse cells in edit mode

I find that if you set the table mode in edit mode, after scrolling the table after deleting the row, the cell edit control (red minus sign on the left) is in a random state (rotated vertically or horizontally) on the remaining cells when scrolling the table. Presumably because I'm reusing cells like this:

cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

How to force the edit control to be in the correct state for each cell? It should always be in the horizontal state by default, unless I touch it to remove the cell.

EDIT: Here is 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; } 
+4
source share
2 answers

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

This solved my problem.

+7
source

I just checked in the UITableView, which was useful to me, and I don't see this problem. I use dequeueReusableCellWithIdentifier: like you (without an if statement, of course). Are you doing something special with scrolling or deleting multiple lines or something else?

(I would make this comment, but still cannot. I will delete it as soon as you solve your problem.)

0
source

Source: https://habr.com/ru/post/1487136/


All Articles