SoFunction
Updated on 2025-04-08

iOS11 solution to UITableView side-sliding and removing infinite stretching

Preface

This article mainly introduces to you the relevant content on iOS11 solving the problem of UITableView side sliding removal and unlimited stretching. It is shared for your reference and learning. I won’t say much below. Let’s take a look at the detailed introduction together.

- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
 ...
}

If iOS11 still uses the above method to handle the side-slide deletion function, you will find that the side-slide unlimited stretching, and then automatically call the delete method

iOS11 new method

- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)){
 if (@available(iOS 11.0, *)) {
  
  NSString *title = @"Top";
  if ( == 0) {
   title = @"Cancel the top";
  } else {
   title = @"Top";
  }
  UIContextualAction *topAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:title handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
   
   ...
   
   // This sentence is very important. Exit editing mode and hide the left scroll menu   [tableView setEditing:NO animated:YES];
   completionHandler(true);
  }];
  
  UIContextualAction *deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"delete" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
   
   // This sentence is very important. Exit editing mode and hide the left scroll menu   [tableView setEditing:NO animated:YES];
   completionHandler(true);
  }];
  
  UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[deleteAction,topAction]];
  // No side-slip wireless stretching   = NO;
  return actions;
 }else{
  return nil;
 }
}

Before iOS11, side-sliding wireless stretching will not occur

Summarize

The above is the entire content of this article. I hope that the content of this article has a certain reference value for everyone's study or work. If you have any questions, you can leave a message to communicate. Thank you for your support.