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



我的UITableView有两个自定义单元格:cell1 &cell2

我的UITableView显示一个或另一个取决于enum值。

如果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;
    >     }

这是iOS 8的bug。一个简单的解决方法是在UITableViewCell子类中重写prepareForReuse,如下所示:

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

我有同样的问题在一个表视图中,我有可重新排序的细胞而不是可重新排序的细胞。我尝试了一些解决方案(不同的可重用标识符,…),我发现的解决方案是设置属性showsReorderControl为YES在我的setter。

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

希望有帮助

我在iOS 8测试版中遇到了同样的问题。

我发现当表是在编辑模式有两个视图是UITableViewCell负责表编辑的一部分;这些是uitableviewcellleditcontrol和UITableViewCellReorderControl。第一次创建表时,这两个视图都存在,一切正常,但是当表被重新加载/滚动时,这些视图就消失了。

我认为这个问题是在Beta版本,我在iOS 8 Beta 2版本上尝试过,问题仍然存在。

我们可能要等到下一个版本了

我一直有同样的问题…IOS 8 beta 2.

我已经发现问题是在单元格"dequeueReusableCellWithIdentifier"区域的某个地方。一旦单元格被滚动并使用可重复使用的单元格,所有的删除和移动图像就会消失。

作为一种解决方法(该代码仍在测试中),我取出了用于重用和注册单元格的代码…

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

并替换为这个(在cellForRowAtIndexPath).....

let cell = UITableViewCell()

…这一切都行得通。我知道这不是一个真正的解决方案(许多未使用的单元飞来飞去),但它已经让我解决了进一步编码的问题。当问题解决后,我会回来添加dequeue代码。

PS……这可能是一个评论,但我刚刚开始stackoverflow,没有足够的点来评论。

iOS 8测试版问题。

最新更新