“This is the first day of my participation in the First Challenge 2022. For details: First Challenge 2022.”
preface
Tidy up the UITableview cell left swipe delete attention points, implement a simple left swipe delete function. The process of finishing is also a regression process, sometimes some functions have not been written for a long time and forget the implementation method of the system.
IOS11 editActionsForRowAtIndexPath method before temporarily don’t fit, can know to adaptation iOS10 version
New system sideslip method in iOS11
The new method in ios11 supports image and text slide styles, the default style is image on top, text on bottom. Another thing to note here is that when the cell height is small, only image is displayed and title is not displayed. When the cell height is large enough, both image and title are displayed.
// Swipe actions // These methods supersede -editActionsForRowAtIndexPath: if implemented // return nil to get the default swipe actions - (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView leadingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE (ios (11.0)) API_UNAVAILABLE (tvos); - (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView TrailingSwipeActionsConfigurationForRowAtIndexPath: (NSIndexPath *) indexPath API_AVAILABLE (ios (11.0)) API_UNAVAILABLE(tvos);Copy the code
Left-swipe style handling in different system versions
- (void)setupSlideBtn {if (@available(iOS 13.0, *)) { for (UIView *subView in self.detailTableView.subviews) { if ([subView isKindOfClass:NSClassFromString(@"_UITableViewCellSwipeContainerView")] && [subView.subviews count] >= 1) { UIView *remarkContentView = subView.subviews.firstObject; [self setupRowActionViewInit: remarkContentView]; } } return; } the if (@ the available (iOS 11.0, *)) { for (UIView *subView in self.detailTableView.subviews) { if ([subView isKindOfClass:NSClassFromString(@"UISwipeActionPullView")] && [subView.subviews count] >= 1) { UIView *remarkContentView = subView; remarkContentView.backgroundColor = [UIColor clearColor]; [self setupRowActionViewInit: remarkContentView]; } } return; } / / the following iOS11 version UITableViewCell * cell = [self. DetailTableView cellForRowAtIndexPath: self. EditingIndexPath]; for (UIView *subView in cell.subviews) { if ([subView isKindOfClass:NSClassFromString(@"UITableViewCellDeleteConfirmationView")] && [subView.subviews count] >= 1) { UIView *remarkContentView = subView; [self setupRowActionViewInit:remarkContentView]; }}}Copy the code
Customize cell height left – swipe style processing
The default system style is the height of the cell. If the height of the View displayed in the cell is different from that of the cell itself, this will be handled
The demo link
Refer to the link
Juejin. Cn/post / 684490… IOS custom left or side swipe delete for iOS13 or later