ios cell左滑删除
iOS项目开发小技能 (三) -UITableView实现Cell左划删除等自定义功能
今天来介绍下iOS开发中UITableView的Cell左划实现微信中置顶,删除等功能。该功能在iOS8.0以前是需要很复杂的实现,不过github上应该有现成demo,不过今天介绍的是在iOS8.0以后苹果新推出的api,来实现Cell左划自定义控件。
1. 首先创建UITableView视图,实现其俩个代理,UITableViewDelegate和UITableViewDataSource,该处代码就不说了,主要是俩个回调方法 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
和-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
2. 然后实现另一个代理方法 -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
editingStyle = UITableViewCellEditingStyleDelete;//此处的EditingStyle可等于任意UITableViewCellEditingStyle,该行代码只在iOS8.0以前版本有作用,也可以不实现。
}
3. 再实现
`-(NSArray )tableView:(UITableView )tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewRowAction *deleteRoWAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@”删除” handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {//title可自已定义
NSLog(@”点击删除”);
}];//此处是iOS8.0以后苹果最新推出的api,UITableViewRowAction,Style是划出的标签颜色等状态的定义,这里也可自行定义
UITableViewRowAction *editRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"编辑" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
}];
editRowAction.backgroundColor = [UIColor colorWithRed:0 green:124/255.0 blue:223/255.0 alpha:1];//可以定义RowAction的颜色
return @[deleteRoWAction, editRowAction];//最后返回这俩个RowAction 的数组
}`
这样就实现了如下的效果
最新文章
- 转换成的jar文件接收后台的信息乱码cmd解决办法
- ESASP 业界第一个最为完善的 ASP MVC框架(待续)
- 解决方案:Error:Execution failed for task ':app:compileDebugAidl'. >; aidl is missing
- Delphi IP 控件源码
- 关于 hot code replace fail 问题 .
- poj 3281 最大流建图
- 使用mysql作为hive的元数据库
- 如何禁止KEIL初始化RAM为零&; 如何判断是软复位还是上电复位
- js中()()问题
- PHP5生成图形验证码(有汉字)
- ActiveMQ in Action(2) - Transport
- LeetCode 152. Maximum Product Subarray (最大乘积子数组)
- 两行 CSS 代码实现 PNG 任意颜色赋色技术
- Solr搜索引擎搭建详细过程
- vue前端开发。。。
- Maven - pom中的<;repository>; <;pluginRepositories>;
- ogma
- 我了解到的新知识之----遇到路由器DNS被篡改我该怎么办?
- UVa540
- 树的dfs序.欧拉序
热门文章
- bootstrap搜索框样式代码及效果
- php运行出现Call to undefined function curl_init()的解决方法
- 关于outerWidth()属性
- Effective Java 读书笔记之二 对于所有对象都通用的方法
- android socket编程用Bufferreader读取的一个失败教训
- Android学习笔记(十九)——内容提供器
- Retina视网膜屏中CSS3边框图片像素虚边的问题
- 2016年11月2日--Window.document对象
- Qt5 托盘模仿qq闪烁,弹消息框实现
- BZOJ 1419: Red is good