前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >iOS 11 editActionsForRowAtIndexPath

iOS 11 editActionsForRowAtIndexPath

作者头像
程序员不务正业
发布2018-06-14 15:34:21
8100
发布2018-06-14 15:34:21
举报

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

Demo

代码语言:javascript
复制
// iOS 11 新特性 左边侧滑

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

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

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

代码语言:javascript
复制
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;
代码语言:javascript
复制
- (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;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017.09.25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 直接进行左右两边进行侧滑操作
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档