iOS tableView编辑添加多个按钮

iOS 新的属性

typedef NS_ENUM(NSInteger, UITableViewRowActionStyle) {

    UITableViewRowActionStyleDefault =0,

    UITableViewRowActionStyleDestructive =UITableViewRowActionStyleDefault,

    UITableViewRowActionStyleNormal

} NS_ENUM_AVAILABLE_IOS(8_0);

 

NS_CLASS_AVAILABLE_IOS(8_0)@interface UITableViewRowAction :NSObject <NSCopying>

 

+ (instancetype)rowActionWithStyle:(UITableViewRowActionStyle)style title:(NSString *)title handler:(void (^)(UITableViewRowAction *action, NSIndexPath *indexPath))handler;

/下面实现相关代码

 

(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{

    

    returnYES;

}

 

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

 

{

    

    return UITableViewCellEditingStyleDelete;

    

}

 

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{

    

    if (editingStyle ==UITableViewCellEditingStyleDelete) {

        

        [self.dataSourceremoveObjectAtIndex:indexPath.row];

        [self.tableViewdeleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];

    }

}

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{

    

    //设置删除按钮

      UITableViewRowAction *deleteRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDestructivetitle:@"删除"handler:^(UITableViewRowAction *action,NSIndexPath *indexPath) {

          

          [self.dataSourceremoveObjectAtIndex:indexPath.row];

          [self.tableViewdeleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];

          

      }];

    

    //设置收藏按钮

    UITableViewRowAction *collectRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDefaulttitle:@"收藏"handler:^(UITableViewRowAction *action,NSIndexPath *indexPath) {

        

      

        collectRowAction.backgroundColor = [UIColorgreenColor];

 

        UIAlertView *alertView = [[UIAlertViewalloc]initWithTitle:@"收藏"message:@"收藏成功"delegate:selfcancelButtonTitle:@"确定"otherButtonTitles:nil,nil];

        [alertView show];

        

        

    }];

    //设置置顶按钮

    UITableViewRowAction *topRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDefaulttitle:@"置顶"handler:^(UITableViewRowAction *action,NSIndexPath *indexPath) {

 

        

        [self.dataSourceexchangeObjectAtIndex:indexPath.rowwithObjectAtIndex:0];

        

        NSIndexPath *firstIndexPath = [NSIndexPathindexPathForRow:0inSection:indexPath.section];

        [tableView moveRowAtIndexPath:indexPathtoIndexPath:firstIndexPath];

        

    }];

    

    collectRowAction.backgroundEffect = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleLight];

    topRowAction.backgroundColor = [UIColorblueColor];

    collectRowAction.backgroundColor = [UIColorgrayColor];

    

    return  @[deleteRowAction,collectRowAction,topRowAction];

}

 


 

转载于:https://www.cnblogs.com/LynnAIQ/p/5952851.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值