一:UITableView 自带编辑删除

1:实现两个方法就可以

#pragma mark   tableView自带的编辑功能

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

    //方法实现后。默认实现手势滑动删除的方法

    if (editingStyle!=UITableViewCellEditingStyleDelete) {

        return ;

    }

    _attentionTableView.editing = !_attentionTableView.editing;

    //删除店铺收藏

    [goods_bll
deleteCollectShopWithStoreId:[collectShopAry[indexPath.row]
objectForKey:@"storeId"]
andUid:userUidStr
success:^(id json) {

        [self
getCollectShop];

    } faile:^{

    }];

}

#pragma mark 选择编辑的样式

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

    return
UITableViewCellEditingStyleDelete;//手势滑动删除

}

2:实现这两个方法实现自带的删除。此时删除button为英文delete ,假设想改变内容,变成中文删除或是别的内容。须要实现以下的方法

#pragma mark 中引文转换-delete

-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath
*)indexPath{

    return
@"删除";

}

3:

**

 *  tableView:editActionsForRowAtIndexPath:     // 设置滑动删除时显示多个button

 *  UITableViewRowAction                        // 通过此类创建button

 *  1. 我们在使用一些应用的时候,在滑动一些联系人的某一行的时候,会出现删除、置顶、很多其它等等的button,在iOS8之前,我们都须要自己去实现。But。到了iOS8,系统已经写好了,仅仅须要一个代理方法和一个类就搞定了

 *  2. iOS8的协议多了一个方法,返回值是数组的tableView:editActionsForRowAtIndexPath:方法,我们能够在方法内部写好几个button,然后放到数组中返回,那些button的类就是UITableViewRowAction

 *  3. 在UITableViewRowAction类,我们能够设置button的样式、显示的文字、背景色、和button的事件(事件在Block中实现)

 *  4. 在代理方法中,我们能够创建多个button放到数组中返回。最先放入数组的button显示在最右側,最后放入的显示在最左側

 *  5. 注意:假设我们自己设定了一个或多个button,系统自带的删除button就消失了...

 */

#pragma mark 在滑动手势删除某一行的时候,显示出很多其它的button

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

{

    // 加入一个删除button

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

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

        

        // 1. 更新数据

        [_allDataArray removeObjectAtIndex:indexPath.row];

        // 2. 更新UI

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

    }];

    

    // 删除一个置顶button

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

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

        

        // 1. 更新数据

];

        

        // 2. 更新UI

        inSection:indexPath.section];

        [tableView moveRowAtIndexPath:indexPathtoIndexPath:firstIndexPath];

    }];

    topRowAction.backgroundColor = [UIColor blueColor];

    

    // 加入一个很多其它button

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

        NSLog(@"点击了很多其它");

        

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

    }];

    moreRowAction.backgroundEffect = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleDark];

    

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

    return @[deleteRowAction, topRowAction, moreRowAction];

}

UITableView 自带编辑删除 自己定义button的更多相关文章

  1. GridView总结二:GridView自带编辑删除更新

    GridView自带编辑删除更新逻辑很简单:操作完,重新绑定.总结总结,防止忘记... 效果图: 前台代码: <%@ Page Language="C#" AutoEvent ...

  2. 自定义UITableview自带侧滑删除按钮样式 by 徐

    效果如下: 实现原理: 1.打开tableview自带的侧滑删除功能 核心代码: 1 -(void)tableView:(UITableView *)tableView commitEditingSt ...

  3. UITableVIew与UICollectionView带动画删除cell时崩溃的处理

    UITableVIew与UICollectionView带动画删除cell时崩溃的处理 -会崩溃的原因是因为没有处理好数据源与cell之间的协调关系- 效果: tableView的源码: ModelC ...

  4. UI学习笔记---第十天UITableView表视图编辑

    UITableView表视图编辑 表视图编辑的使用场景 当我们需要手动添加或者删除某条数据到tableView中的时候,就可以使用tableView编辑.比如微信 扣扣中删除和某人的通话 当我们需要手 ...

  5. GridView编辑删除操作

    第一种:使用DataSource数据源中自带的编辑删除方法,这样的不经常使用,在这里就不加说明了. 另外一种:使用GridView的三种事件:GridView1_RowEditing(编辑).Grid ...

  6. Activiti 删除流程定义

    package com.mycom.processDefinition; import java.io.InputStream; import java.util.List; import java. ...

  7. Qt之模型/视图(自己定义button)

    简述 衍伸前面的章节,我们对QTableView实现了数据显示.自己定义排序.显示复选框.进度条等功能的实现.本节主要针对自己定义button进行解说.这节过后,也希望大家对自己定义有更深入的了解.在 ...

  8. wordpress后台编辑如何显示定义的`style.css`样式

    wordpress后台编辑如何显示定义的style.css样式 由于公司官网采用wordpress进行搭建,但是却又自己设计页面,无奈主题只能自行构建了,直接修改wordpress自带的主题进行修改. ...

  9. Android实现自定义带文字和图片的Button

    Android实现自定义带文字和图片的Button 在Android开发中经常会需要用到带文字和图片的button,下面来讲解一下常用的实现办法. 一.用系统自带的Button实现 最简单的一种办法就 ...

随机推荐

  1. hdu6074[并查集+LCA+思维] 2017多校4

    看了标答感觉思路清晰了许多,用并查集来维护全联通块的点数和边权和. 用另一个up[]数组(也是并查集)来保证每条边不会被重复附权值,这样我们只要将询问按权值从小到大排序,一定能的到最小的边权和与联通块 ...

  2. HDU——4162Shape Number(字符串的最小表示)

    Shape Number Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  3. wireshark中的抓包过滤器和显示过滤器

    一  抓包过滤器 语法说明:BPF语法(Berkeley Packet Filter) 类型Tpye:host,net,port 方向Dir:src,dst 协议Proto:ether,ip,tcp, ...

  4. 添加gitlab远程账号 使用注意事项

    gitlab上面使用的密钥有两种,一种是Deploy keys 这种密钥是只读的,添加了之后,相应设备只拥有clone的权限,不被允许进行push操作.(在相应的库里面的设置里面添加) 还有一种是 S ...

  5. AC日记——Count on a tree bzoj 2588

    Description 给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lastans和v这两个节点间第K小的点权.其中lastans是上一个询问的答案,初始 ...

  6. Linux字符模式下如何设置/删除环境变量

    Linux字符模式下设置/删除环境变量方法: bash下 设置:export 变量名=变量值 删除:unset 变量名 csh下 设置:setenv 变量名 变量值 删除:unsetenv 变量名 h ...

  7. Java-HashMap原理解析

    本文分析HashMap的实现原理. 数据结构(散列表) HashMap是一个散列表(也叫哈希表),用来存储键值对(key-value)映射.散列表是一种数组和链表的结合体,结构图如下: 简单来说散列表 ...

  8. windows XP 下的DTRACE 跟踪 学习

    https://github.com/prash-wghats/DTrace-win32 1. dtrace_loader.exe -l //to load dtrace drivers 2. C:\ ...

  9. [bug]Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding

    写在前面 在mysql中这个异常是非常常见的,超时分为连接超时和执行超时,而连接超时,大部分原因是网络问题,或客户端到服务端的端口问题造成. bug场景 有的时候,使用MySqlDataReader在 ...

  10. 四个很好的开源app项目

    Open Source and the iOS App Store Today, we are open-sourcing 4 iOS apps: ThatInbox, an email client ...