iOS 11 editActionsForRowAtIndexPath

iOS 11下 editActionsForRowAtIndexPath被替换成两个新的代理

Demo

// iOS 11 新特性 左边侧滑

- (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView leadingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {
}

// iOS 11 新特性 右边侧滑
- (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {
}

直接进行左右两边进行侧滑操作

UIKIT_EXTERN API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos)
@interface UIContextualAction : NSObject

+ (instancetype)contextualActionWithStyle:(UIContextualActionStyle)style title:(nullable NSString *)title handler:(UIContextualActionHandler)handler;

@property (nonatomic, readonly) UIContextualActionStyle style;
@property (nonatomic, copy, readonly) UIContextualActionHandler handler;

@property (nonatomic, copy, nullable) NSString *title;
@property (nonatomic, copy, nullable) UIColor *backgroundColor; // a default background color is set from the action style
@property (nonatomic, copy, nullable) UIImage *image;
- (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {
  
    ICCollectionBaseCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (@available(iOS 11.0, *)) {
        UIContextualAction *shareRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
            [self selectBtnClicked:cell];
            if ([self.delegate respondsToSelector:@selector(didClickForwardBtn:)]) {
                [self.delegate didClickForwardBtn:cell];
            }
            completionHandler(YES);
        }];
        shareRowAction.image = [UIImage imageNamed:@"icon_collection_slide_share"];
        shareRowAction.backgroundColor = BACKGROUNDCOLOR;
        
        UIContextualAction *deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
            [self selectBtnClicked:cell];
            if ([self.delegate respondsToSelector:@selector(didClickDeleteBtn:)]) {
                [self.delegate didClickDeleteBtn:cell];
            }
            completionHandler(YES);
        }];
        deleteRowAction.image = [UIImage imageNamed:@"icon_collection_slide_delete"];
        deleteRowAction.backgroundColor = BACKGROUNDCOLOR;
        
        UISwipeActionsConfiguration *config = [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction, shareRowAction]];
        return config;
    } else {
        // Fallback on earlier versions
    }
    return nil;
}

你可能感兴趣的:(iOS 11 editActionsForRowAtIndexPath)