在UITableview的编辑模式下滚动时删除按钮消失

时间:2017-03-28 05:24:49

标签: ios objective-c uitableview

我在编辑模式下滚动tableview时遇到问题。这是因为细胞的可重用性。我按照链接 - UITableView in Edit Mode - Delete Button Dissapears on Scroll

一无所获。

这是我的代码段 -

- (void)setEditing:(BOOL)editing
      animated:(BOOL)animated
{
   [super setEditing:editing animated:animated];
   [tableView setEditing:editing animated:animated];
   [tableView setAllowsMultipleSelectionDuringEditing:editing];

}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
   return UITableViewCellEditingStyleDelete;
}


- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath 
{
   return NO;
}


- (BOOL)tableView:(UITableView *)tableview canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
   return YES;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

   if (cell == nil)
    {
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];

    }

 [cell setEditingAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];

 cell.textLabel.text=[NSString stringWithFormat:@"%ld",indexPath.row+1];
 cell.detailTextLabel.text=@"";


 cell.clipsToBounds = YES;
 return cell;
}

Delete button behavior on scrolling

那么任何人的建议或建议如何解决该问题?

谢谢。

2 个答案:

答案 0 :(得分:3)

-(void)setEditing:(BOOL)editing animated:(BOOL)animated方法更改为:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated{
    _myTV.allowsMultipleSelectionDuringEditing = NO;
    [super setEditing:editing animated:animated];

    if(editing) {
        [_myTV setEditing:YES animated:YES];
    } else {
        [_myTV setEditing:NO animated:YES];
    }
}

答案 1 :(得分:0)

- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath 
{
   return YES; // return yes
}

现在运行你的程序,让我知道发生了什么?

  

修改

here获取此演示。给出了很好的exlanation