滚动表时,UITableViewCell重新排序控件消失

Jus*_*ore 5 uitableview ios

我的UITableView有2个自定义单元格:cell1和cell2

我的UITableView根据枚举值显示一个或另一个.

如果enumValue == 0,则显示cell1,如果enumValue> 0,则表不允许重新排序,显示cell2且表应允许重新排序

一切正常.随着枚举值的变化,重新排序控件会正确显示.

我的问题:当重新排序控件出现在单元格上时,当行被滚动到视图外时它们将消失.为什么会这样?

抱歉格式和粗略的代码.我对网站没有任何问题.有什么明显的突出可能导致这个?

> // 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;
    >     }
Run Code Online (Sandbox Code Playgroud)

Vad*_*gin 18

这是iOS 8的错误.一个简单的解决方法是prepareForReuseUITableViewCell子类中覆盖,如下所示:

- (void)prepareForReuse
{
    [super prepareForReuse];
    [self setEditing:NO animated:NO];
}
Run Code Online (Sandbox Code Playgroud)