iOS开发笔记(4) -- UITableView的左滑删除与自定义
来源:互联网 发布:centos虚拟机不能上网 编辑:程序博客网 时间:2024/04/29 01:33
无可争议,在iOS开发中UITableView的使用当之无愧是最频繁的视图之一,同时当使用UITableView是操作cell左滑删除也会随之被经常使用;
不废话上代码;
首先说一下单一按钮情况:
//设置你的滑块标题- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{ return @"Delete";}//如果你是删除功能那么一定不要忘记删除数据源中的对应数据,不然...血的教训- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ // 从数据源中删除 [self.array removeObjectAtIndex:indexPath.row]; // 从列表中删除 [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];}//将tableview设为可编辑状态- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{ return YES;}
接下来说一下多个滑块的情况:
-(NSArray<UITableViewRowAction*>*)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewRowAction *renameAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Rename" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) { NSLog(@"重命名"); }]; UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Delete" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) { // 从数据源中删除 [self.array removeObjectAtIndex:indexPath.row]; // 从列表中删除 [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; }]; renameAction.backgroundColor = UIColorFromRGB(0x87caf8); deleteAction.backgroundColor = UIColorFromRGB(0xfc665e); NSArray *actionArr = @[renameAction,deleteAction]; return actionArr;}
1 0
- iOS开发笔记(4) -- UITableView的左滑删除与自定义
- iOS开发中实现UITableView的Cell左划删除等自定义功能
- iOS开发之UITableView中Cell左滑自定义事件
- 【支持iOS11】UITableView左滑删除自定义
- iOS项目开发小技巧 (三) --UITableView实现Cell左划删除等自定义功能
- iOS UITableView 左滑删除cell
- IOS UITableView实现左滑删除
- UITableView左滑 删除
- UITableView左滑删除
- UITableView 左滑删除
- UITableView自定义左滑删除按钮(带图片)
- ios实现UITableView左滑删除-复制即用
- UITableView 左滑删除cell
- UIScrollView滑动与UITableView左滑删除冲突问题解决方案
- UITableView 编辑状态下的批量选择与左滑删除等随笔
- iOS开发笔记>> UIButton与UITableView的层级结构
- iOS开发:UITableView实现侧滑删除cell的功能
- iOS UITableView(一)-纯代码创建UITableView,Cell点击事件,Cell左滑删除
- ReactNative的Navigator组件使用方式
- UUID解析与使用
- TextView的常用属性
- 测试数据库最多连接数
- linux密码故障解决
- iOS开发笔记(4) -- UITableView的左滑删除与自定义
- HDU
- 程序员找工作二三事【智库2861】
- 常用的JQ函数
- 2017.4.5 开发日记
- 连接数据库
- oracle数据库开发之自增列
- ButterKnife的学习和使用
- 微信支付