5
votes

My UITableView has 2 custom cells: cell1 & cell2

My UITableView displays one or the other depending on an enum value.

If enumValue == 0, cell1 is shown and the table should not allow reordering if enumValue > 0, cell2 is shown and the table should allow reordering

All that is working fine. The reorder controls are displayed appropriately as the enum values change.

My problem: When the reorder controls appear on the cell, they will disappear when the row is scrolled out of view. Why is this happening?

Sorry about the formatting and rough code. I was haven't issues with the site. Anything obvious stand out that could be causing this?

> // enum
> 
> -(void)setScorePhase:(phase)scorePhase {
> 
>     _scorePhase = scorePhase;
>     
>     if (scorePhase > score) {
>         self.btnPrevious.hidden = NO;
>         [self.tableCorps setEditing:YES animated:YES];
>     } else {
>         self.btnPrevious.hidden = YES;
>         [self.tableCorps setEditing:NO animated:YES];
>     }
>     
>     switch (scorePhase) {
>         case score:
>             self.lblInstructions.text = @"Give your scores";
>             self.btnNext.titleLabel.text = @"Next";
>             break;
>         case bestdrums:
>             self.lblInstructions.text = @"Order the corps by best percussion";
>             self.btnNext.titleLabel.text = @"Next";
>             break;
>         case besthornline:
>             self.lblInstructions.text = @"Order the corps by best hornline";
>             self.btnNext.titleLabel.text = @"Next";
>             break;
>         case bestguard:
>             self.lblInstructions.text = @"Order the corps by best colorguard";
>             self.btnNext.titleLabel.text = @"Next";
>             break;
>         case loudesthornline:
>             self.lblInstructions.text = @"Order the corps by loudest hornline";
>             self.btnNext.titleLabel.text = @"Next";
>             break;
>         case favorite:
>             self.lblInstructions.text = @"Order the corps by your favorite";
>             self.btnNext.titleLabel.text = @"Submit";
>             break;
>             
>         default:
>             self.lblInstructions.text = @"Error";
>             break;
>     }
>     [self.tableCorps reloadData]; 
}




>

        -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    >         
    >         return 2;
    >     }
    >     
    >     -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    >         
    >         switch (section) {
    >             case 0: return @"World Class";
    >             case 1: return @"Open Class";
    >             default: return @"Error";
    >         }
    >     }
    >     
    >     - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    >         
    >         if ([self.arrayOfPerformingCorps count]) {
    >             switch (section) {
    >                 case 0: return [self.arrayOfWorldClass count];
    >                 case 1: return [self.arrayOfOpenClass count];
    >                 default: return 0;
    >             }
    >         } else {
    >             return 0;
    >         }
    >     }
    >     
    >     -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    >         
    >         UITableViewCell *cell;
    >         if (self.scorePhase == score) {
    >             cell = [self.tableCorps dequeueReusableCellWithIdentifier:@"cell1"];
>cell.showsReorderControl = NO;
    >             
    >         } else {
    >             cell = [self.tableCorps dequeueReusableCellWithIdentifier:@"cell2"];
>cell.showsReorderControl = YES;
    >             
    >         }
    >         
    >         
    >         PFObject *corps;
    >         if ([self.arrayOfPerformingCorps count]) {
    >             if ((int)[indexPath section] == 0) {
    >                 corps = [self.arrayOfWorldClass objectAtIndex:[indexPath row]];
    >             } else {
    >                 corps = [self.arrayOfOpenClass objectAtIndex:[indexPath row]];
    >             }
    >             
    >             UILabel *corpsNameLabel = (UILabel *)[cell viewWithTag:0];
    >             corpsNameLabel.text = corps[@"corpsName"];
    >             
    >             
    >         } else {
    >             //cell.textLabel.text = @"";
    >             //cell.detailTextLabel.text = @"";
    >         }
    >         
    >         return cell;
    >     }
    >     
    >     #pragma  mark - Table Reordering
    >     - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    >         if (self.scorePhase > score) return YES;
    >         else return NO;
    >     }
    >     - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    >         return UITableViewCellEditingStyleNone;
    >     }
    >     - (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
    >         return NO;
    >     }
    >     - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    >         return YES;
    >     }
    >     - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath
    > toIndexPath:(NSIndexPath *)destinationIndexPath{
    >         
    >     }
    >     
    >     - (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath
    > *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
    >     {
    >         if (sourceIndexPath.section != proposedDestinationIndexPath.section) {
    >             NSInteger row = 0;
    >             if (sourceIndexPath.section < proposedDestinationIndexPath.section) {
    >                 row = [tableView numberOfRowsInSection:sourceIndexPath.section] - 1;
    >             }
    >             return [NSIndexPath indexPathForRow:row inSection:sourceIndexPath.section];
    >         }
    >         
    >         return proposedDestinationIndexPath;
    >     }
5
After further testing, I believe this is an iOS 8 beta issue.Justin Moore
Im facing the same problem as well. Im inclined to believe its a problem with the iOS 8 beta as well.cybervedaa

5 Answers

18
votes

This is iOS 8 bug. A simple workaround is to override prepareForReuse in the UITableViewCell subclass like this:

- (void)prepareForReuse
{
    [super prepareForReuse];
    [self setEditing:NO animated:NO];
}
2
votes

I had the same issue in a Table View where I had reorderable cells dans not reorderable cell. I tried some solutions (different reusable identifiers, ...) the solution I found was to set the property showsReorderControl to YES in my setter.

self.showsReorderControl = reorderable;
[self setEditing:reorderable animated:NO];

Hope that helps

0
votes

I am facing the same issue with iOS 8 beta version.

I figured out when the table is on edit mode there two view that are part of UITableViewCell which are responsible for table edit; these are, UITableViewCellEditControl and UITableViewCellReorderControl. Both of these views are present the first time table is created and everything works fine, but as the table gets reloaded/scrolled these views disappears.

I think this problem is with Beta version, I tried it with iOS 8 Beta 2 version and the problem still persist.

We might have to wait for the next release.

0
votes

I've been having the same issue...IOS 8 beta 2.

I've figured out that the problem is somewhere in the cell "dequeueReusableCellWithIdentifier" area. As soon as the cells are scrolled and it uses a reusable cell, all the delete and move images disappear.

As a workaround (this code is still in test), I took out the code for reusing and registering cells...

tableViewFromNib.registerClass(myViewControllerCell.self, forCellReuseIdentifier: cellReuseID)
     .
     .
let cell = tableView!.dequeueReusableCellWithIdentifier(cellReuseID, forIndexPath: indexPath) as myViewControllerCell 

and replaced it with this (in cellForRowAtIndexPath).....

let cell = UITableViewCell()

....it all works. I know that's not a real solution (lots of unused cells flying around), but it has gotten me past the issue for further coding. I will come back and add the dequeue code later when the issue is fixed.

PS...this probably could have been a comment, but I just started stackoverflow and don't have enough points to comment.

-1
votes

iOS 8 beta issue. Not an issue with code.