UITableView 自带编辑删除 自己定义button
一: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的更多相关文章
- GridView总结二:GridView自带编辑删除更新
GridView自带编辑删除更新逻辑很简单:操作完,重新绑定.总结总结,防止忘记... 效果图: 前台代码: <%@ Page Language="C#" AutoEvent ...
- 自定义UITableview自带侧滑删除按钮样式 by 徐
效果如下: 实现原理: 1.打开tableview自带的侧滑删除功能 核心代码: 1 -(void)tableView:(UITableView *)tableView commitEditingSt ...
- UITableVIew与UICollectionView带动画删除cell时崩溃的处理
UITableVIew与UICollectionView带动画删除cell时崩溃的处理 -会崩溃的原因是因为没有处理好数据源与cell之间的协调关系- 效果: tableView的源码: ModelC ...
- UI学习笔记---第十天UITableView表视图编辑
UITableView表视图编辑 表视图编辑的使用场景 当我们需要手动添加或者删除某条数据到tableView中的时候,就可以使用tableView编辑.比如微信 扣扣中删除和某人的通话 当我们需要手 ...
- GridView编辑删除操作
第一种:使用DataSource数据源中自带的编辑删除方法,这样的不经常使用,在这里就不加说明了. 另外一种:使用GridView的三种事件:GridView1_RowEditing(编辑).Grid ...
- Activiti 删除流程定义
package com.mycom.processDefinition; import java.io.InputStream; import java.util.List; import java. ...
- Qt之模型/视图(自己定义button)
简述 衍伸前面的章节,我们对QTableView实现了数据显示.自己定义排序.显示复选框.进度条等功能的实现.本节主要针对自己定义button进行解说.这节过后,也希望大家对自己定义有更深入的了解.在 ...
- wordpress后台编辑如何显示定义的`style.css`样式
wordpress后台编辑如何显示定义的style.css样式 由于公司官网采用wordpress进行搭建,但是却又自己设计页面,无奈主题只能自行构建了,直接修改wordpress自带的主题进行修改. ...
- Android实现自定义带文字和图片的Button
Android实现自定义带文字和图片的Button 在Android开发中经常会需要用到带文字和图片的button,下面来讲解一下常用的实现办法. 一.用系统自带的Button实现 最简单的一种办法就 ...
随机推荐
- Nginx报 No input file specified. 的问题解决之路 转
https://m.aliyun.com/yunqi/articles/34240 今天接手公司的一个项目,照例将项目clone下来,配置本地host,nginx,然后访问. 怎么回事?迅速在php的 ...
- centos中简易安装docker
centos中简易安装docker准备环境要求:请确保自己的centos的内核版本大于3.10,使用如下linux命令: uname -r1显示如下类似信息: 3.10.0-862.3.3.el7.x ...
- 大杂烩 Classpath / Build path / Debug关联源码 / JDK&JRE区别
Classpath的理解及其使用方式 原文地址:http://blog.csdn.net/wk1134314305/article/details/77940147?from=bdhd_site 摘要 ...
- Office 365 切换语言设置
The steps of changing the language: Click “Setting ”>”Office 365 Setting” ...
- CI安全
URI安全,CodeIgniter 严格限制 URI 中所能包含的字符,以此帮助你设计的程序减少被恶意数据入侵的可能.URI 一般只包含下列内容: 字母和数字(Alpha-numeric text) ...
- LeetCode OJ--Longest Consecutive Sequence ***
http://oj.leetcode.com/problems/longest-consecutive-sequence/ 起初想的是排序,查了下O(n)的排序算法有计数排序.基数排序.桶排序.后来考 ...
- Codeforces Gym101606 D.Deranging Hat (2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017))
D Deranging Hat 这个题简直了,本来想的是冒泡排序然后逆着输出来的,后来发现不对,因为题目上求的是最优解,而且冒泡的话,输出结果有的超出10000行了,所以就是把一开始的,排好序的字母标 ...
- arch 安装
xfce参考 http://my.oschina.net/u/1408707/blog/182581#OSC_h2_6 chm阅读 – chmsee作为一个苦逼的码农,要忍受各种chm文件的蹂躏,这个 ...
- Leetcode总结之Union Find
package UnionFind; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; p ...
- Parallel Database for OLTP and OLAP
Parallel Database for OLTP and OLAP Just asurvey article on materials on parallel database products ...