博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS开发cell--滑动手势显示按钮
阅读量:7281 次
发布时间:2019-06-30

本文共 1615 字,大约阅读时间需要 5 分钟。

// 主要代码

#warning iOS8 -

#pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮

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

{

    // 添加一个删除按钮

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

        NSLog(@"点击了删除");

        

        // 1. 更新数据

        [_allDataArray removeObjectAtIndex:indexPath.row];

        // 2. 更新UI

        [tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];

    }];

    

    // 删除一个置顶按钮

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

        NSLog(@"点击了置顶");

        

        // 1. 更新数据

        [_allDataArray exchangeObjectAtIndex:indexPath.row withObjectAtIndex:0];

        

        // 2. 更新UI

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

        [tableView moveRowAtIndexPath:indexPathtoIndexPath:firstIndexPath];

    }];

    topRowAction.backgroundColor = [UIColor blueColor];

    

    // 添加一个更多按钮

    UITableViewRowAction *moreRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleNormal title:@"更多"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {

        NSLog(@"点击了更多");

        

        [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];

    }];

    moreRowAction.backgroundEffect = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleDark];

    

    // 将设置好的按钮放到数组中返回

    return @[deleteRowAction, topRowAction, moreRowAction];

}

 

 

递归方法要尽量少使用,另外栈的大小也有一定的限制,如果过多的递归,容易导致stack overflow

转载地址:http://eezjm.baihongyu.com/

你可能感兴趣的文章
Foundation HTML5 Canvas中的2处错误
查看>>
chcapter 11 熵和信息
查看>>
GFS文件系统
查看>>
面向对象数据库NDatabase_初识
查看>>
HDU1319 POJ1595 UVA406 UVALive5490 ZOJ1312 Prime Cuts【素数筛选+打表】
查看>>
事务的特性及事务的隔离级别(转)
查看>>
转:如何正确彻底删除webpack 全局或是局部?
查看>>
【Python】Symbol Review
查看>>
电脑 F键(功能键)的具体作用
查看>>
004-软件质量保证&QC/QA
查看>>
选择排序的实现以及性能测试
查看>>
基于snowfall的玫瑰花瓣飘落效果
查看>>
linux之cut用法
查看>>
结交比自己优秀的人
查看>>
Home键和back键下 Activity的生命周期变化
查看>>
用MotoMidMan给L7批量安装java程序
查看>>
C语言中main函数之前可以进行赋值作吗?
查看>>
WKWebView Cookie注入
查看>>
组合数据类型,英文词频统计
查看>>
【3】火狐中: radio被点击以后,重刷页面,不会选择默认的radio
查看>>