简体   繁体   English

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

[英]Delete button disappeared on scrolling in edit mode of UITableview

I am facing the issue when I scroll the tableview in edit mode. 我在编辑模式下滚动tableview时遇到问题。 It's because of reusability of cells. 这是因为细胞的可重用性。 I followed the link- UITableView in Edit Mode - Delete Button Dissapears on Scroll 我按照编辑模式中的链接-UITableView - 在滚动上删除按钮消失

Got nothing from that. 什么都没有。

Here is my code snippet- 这是我的代码片段 -

- (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;
}

滚动时删除按钮行为

So any recommendation or suggestion from anyone how to resolve that issue? 那么任何人如何解决该问题的任何建议或建议?

Thank you. 谢谢。

Change -(void)setEditing:(BOOL)editing animated:(BOOL)animated method into this: 更改-(void)setEditing:(BOOL)editing animated:(BOOL)animated方法-(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];
    }
}
- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath 
{
   return YES; // return yes
}

Now run your program and let me know what happening? 现在运行你的程序,让我知道发生了什么?

edit 编辑

Get this demo from here . 这里获取此演示。 Nice exlanation is given 很好的exlanation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UITableView编辑模式不显示删除按钮 - UITableView edit mode not showing delete button UITableView编辑模式删除按钮右侧填充 - UITableView edit mode delete button padding-right 在编辑模式下按删除按钮时,UITableView崩溃 - UITableView crashes when pressing delete button in edit mode UITableView 编辑模式 - 自定义减号删除按钮的颜色 - UITableView edit mode - customize color of minus sign delete button UITableview编辑模式下的删除控制按钮不起作用 - Deletion control button on UITableview edit mode is not working UITableView禁用滑动以删除,但在编辑模式下仍具有删除功能? - UITableView disable swipe to delete, but still have delete in Edit mode? 允许UITableView重新排序,但不能在编辑模式下删除,并启用滑动以删除 - Allow UITableView to reorder, but not delete in edit mode, and enable swipe to delete anyway 在iOS 8.1中,当我在UITableView处于编辑模式时单击行的删除按钮时,该行及其上方的行显示不正确 - In iOS 8.1, when I click on a row's delete button while UITableView is in edit mode, the row and those above it display incorrectly 是否可以在UITableView编辑模式下更改默认删除操作图标? - Is it possible to change default delete action Icon in UITableView edit mode? 在编辑模式下删除表格行上的删除按钮⛔️ - remove the delete button ⛔️ on table rows in edit mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM