IOS 11 Solution to UITableView Side Slip Delete Infinite Stretch

Time:2019-10-6

Preface

This article mainly introduces the iOS11 solution UITableView sideslip deletion infinite stretch related content, share it for your reference and learning, the following words do not say much, let’s take a look at the detailed introduction.


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

If iOS 11 still uses the above method to handle the sideslip deletion function, it will find that the sideslip is infinitely stretched, and then automatically call the deletion method.

IOS 11 adds new methods

- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)){
 if (@available(iOS 11.0, *)) {
  
  NSString * title = @ "top setting";
  if (indexPath.section == 0) {
   Title = @ "Cancel Topping";
  } else {
   Title = @ "top setting";
  }
  UIContextualAction *topAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:title handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
   
   ...
   
   // It's very important to quit editing mode and hide the left-slide menu.
   [tableView setEditing:NO animated:YES];
   completionHandler(true);
  }];
  
  UIContextualAction * deleteAction = [UIContextualAction contextualAction WithStyle: UIContextualAction Style Destructive title: @ "Delete" handler: ^ (UIContextualAction * _Nonnull action, _kindof UIView * _Nonnull sourceView, void (^_Nonnull Handler) (BOOL)){
   
   // It's very important to quit editing mode and hide the left-slide menu.
   [tableView setEditing:NO animated:YES];
   completionHandler(true);
  }];
  
  UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[deleteAction,topAction]];
  // No Side Slip Wireless Tension
  actions.performsFirstActionWithFullSwipe = NO;
  return actions;
 }else{
  return nil;
 }
}

Before iOS 11, no side slip wireless stretching happened

summary

The above is the whole content of this article. I hope that the content of this article will have some reference and learning value for everyone’s study or work. If there is any doubt, you can leave a message to exchange. Thank you for your support for developpaer.