简体   繁体   中英

Delete button disappeared on scrolling in edit mode of UITableview

I am facing the issue when I scroll the tableview in edit mode. It's because of reusability of cells. I followed the link- UITableView in Edit Mode - Delete Button Dissapears on Scroll

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{
    _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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM