iOS项目开发小技巧 (三) --UITableView实现Cell左划删除等自定义功能
来源:互联网 发布:sql server哪本书好 编辑:程序博客网 时间:2024/04/28 03:57
今天来介绍下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 的数组
}`
这样就实现了如下的效果
另附:
iOS8.0以前实现UITableViewCell左划多个标签的Demo参考
- iOS项目开发小技巧 (三) --UITableView实现Cell左划删除等自定义功能
- iOS开发中实现UITableView的Cell左划删除等自定义功能
- UITableView小技巧--实现cell向左滑动删除,编辑等功能
- UITableView小技巧--实现cell向左滑动删除,编辑等功能
- iOS开发:UITableView实现侧滑删除cell的功能
- iOS开发之UITableView中Cell左滑自定义事件
- iOS UITableView 左滑删除cell
- Android 自定义ListView实现左划删除
- 【iOS】UITableView Cell自定义单选功能
- UITableView 左滑删除cell
- 自定义View实现listView的左划删除
- [IOS]UITableView实现Cell的滑动删除
- iOS UITableView(一)-纯代码创建UITableView,Cell点击事件,Cell左滑删除
- iOS开发:XIB之UITableView自定义cell
- IOS UITableView实现左滑删除
- iOS tableviewcell左划自定义(带图片)删除按钮,点击任意地方取消删除的巧妙实现方法
- iOS开发总结之项目开发中使用UITableView自定义多级表格&自定义cell
- ios UITableview自定义cell
- zoj 1002 Fire Net(不能位于同行或同列,问最多放几个)
- Directory类提供的静态方法去处理目录
- hdoj 1024 Max Sum Plus Plus 【动态规划经典题目】【m子段和】
- Cocos2d-x的学习之旅(三)自己的 HelloWorld
- OC第六天
- iOS项目开发小技巧 (三) --UITableView实现Cell左划删除等自定义功能
- 通过IP获取地区省市
- Android 快速开发系列 打造万能的ListView GridView 适配器
- HTML第十九节(回到顶部效果)
- Hibernate HelloWorld-14 批量操作
- 堆排序
- java面向对象编程
- LeetCode 27:Remove Element
- OC第五天-字典,集合,数组排序