iOS开发之UITableView中Cell左滑自定义事件
来源:互联网 发布:女诫 知乎 编辑:程序博客网 时间:2024/04/28 05:05
//自定义左滑操作置顶标记更多等
- (nullable NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(8_0)__TVOS_PROHIBITED{
UITableViewRowAction *top = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleNormaltitle:@"置顶"handler:^(UITableViewRowAction *_Nonnull action,NSIndexPath *_Nonnull indexPath) {
//数据源置顶
NSString *tempObject = [listOneArrayobjectAtIndex:indexPath.row];
[listOneArray removeObject:[listOneArray objectAtIndex:indexPath.row]];
[listOneArray insertObject:tempObject atIndex:0];
// [listOneArray exchangeObjectAtIndex:indexPath.row withObjectAtIndex:0];
//表单移动
//获取顶部的IndexPath
NSIndexPath *topIndexPath = [NSIndexPathindexPathForRow:0inSection:indexPath.section];
//
[tableView moveRowAtIndexPath:indexPathtoIndexPath:topIndexPath];
//
[tableView reloadRowsAtIndexPaths:@[topIndexPath]withRowAnimation:UITableViewRowAnimationRight];
[tableView reloadData];
}];
top.backgroundColor = [UIColorredColor];
UITableViewRowAction *bottom = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleNormaltitle:@"置后"handler:^(UITableViewRowAction *_Nonnull action,NSIndexPath *_Nonnull indexPath) {
//数据源置后
NSString *tempObject = [listOneArrayobjectAtIndex:indexPath.row];
[listOneArray removeObject:[listOneArray objectAtIndex:indexPath.row]];
[listOneArray insertObject:tempObject atIndex:listOneArray.count];
//表单移动
//获取底部的IndexPath
NSIndexPath *bottomIndexPath = [NSIndexPathindexPathForRow:listOneArray.count-1inSection:indexPath.section];
//
[tableView moveRowAtIndexPath:indexPathtoIndexPath:bottomIndexPath];
//
[tableView reloadRowsAtIndexPaths:@[bottomIndexPath]withRowAnimation:UITableViewRowAnimationRight];
[tableView reloadData];
}];
bottom.backgroundColor = [UIColoryellowColor];
UITableViewRowAction *moveUp = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleNormaltitle:@"上移"handler:^(UITableViewRowAction *_Nonnull action,NSIndexPath *_Nonnull indexPath) {
[listOneArrayexchangeObjectAtIndex:indexPath.rowwithObjectAtIndex:indexPath.row-1];//交换数据源
//表单移动
//获取上一个的IndexPath
NSIndexPath *upIndexPath = [NSIndexPathindexPathForRow:indexPath.row-1inSection:indexPath.section];
//
[tableView moveRowAtIndexPath:indexPathtoIndexPath:upIndexPath];
//
[tableView reloadRowsAtIndexPaths:@[upIndexPath]withRowAnimation:UITableViewRowAnimationRight];
[tableView reloadData];
}];
moveUp.backgroundColor = [UIColorgreenColor];
UITableViewRowAction *moveDown = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleNormaltitle:@"下移"handler:^(UITableViewRowAction *_Nonnull action,NSIndexPath *_Nonnull indexPath) {
[listOneArrayexchangeObjectAtIndex:indexPath.rowwithObjectAtIndex:indexPath.row+1];//交换数据源
//表单移动
//获取下一个的IndexPath
NSIndexPath *downIndexPath = [NSIndexPathindexPathForRow:indexPath.row+1inSection:indexPath.section];
//
[tableView moveRowAtIndexPath:indexPathtoIndexPath:downIndexPath];
//
[tableView reloadRowsAtIndexPaths:@[downIndexPath]withRowAnimation:UITableViewRowAnimationRight];
[tableView reloadData];
}];
moveDown.backgroundColor = [UIColorblueColor];
UITableViewRowAction *delete = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleNormaltitle:@"删除"handler:^(UITableViewRowAction *_Nonnull action,NSIndexPath *_Nonnull indexPath) {
[listOneArray removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationRight];
}];
delete.backgroundColor = [UIColorpurpleColor];
UITableViewRowAction *mark = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleNormaltitle:@"标记"handler:^(UITableViewRowAction *_Nonnull action,NSIndexPath *_Nonnull indexPath) {
//标记点击事件方法
}];
mark.backgroundColor = [UIColorblueColor];
UITableViewRowAction *more = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleNormaltitle:@"更多"handler:^(UITableViewRowAction *_Nonnull action,NSIndexPath *_Nonnull indexPath) {
//更多点击事件方法
}];
more.backgroundColor = [UIColorblueColor];
return @[top,bottom,moveUp,moveDown,delete,mark,more];
}
- iOS开发之UITableView中Cell左滑自定义事件
- iOS开发中实现UITableView的Cell左划删除等自定义功能
- iOS开发:XIB之UITableView自定义cell
- iOS UITableView(一)-纯代码创建UITableView,Cell点击事件,Cell左滑删除
- iOS开发总结之项目开发中使用UITableView自定义多级表格&自定义cell
- iOS UITableView 左滑删除cell
- iOS开发 UITableView之cell
- iOS开发UITableView 之代码自定义cell的步骤
- iOS项目开发小技巧 (三) --UITableView实现Cell左划删除等自定义功能
- IOS之UITableView cell自定义视图中插入Tableview
- ios UITableview自定义cell
- UITableView 左滑删除cell
- iOS开发之自定义UITableView
- iOS开发之高级视图—— UITableView(四)自定义Cell
- IOS UITableView 移动自定义cell
- IOS-UITableView 及自定义cell
- IOS-UITableView 及自定义cell
- iOS UITableView(二)-自定义Cell
- svn常用命令纪录
- DDOS攻击原理及防护方法论
- Linux上挂载新硬盘详解
- 常规功能和模块自定义系统 (cfcmms)—026开发日志(创建ManyToMany的column)
- Activity中与ListActivity中使用listview区别
- iOS开发之UITableView中Cell左滑自定义事件
- Android关闭键盘时的一个小问题
- Android实时视频采集方案
- shell 定时器
- iOS Copy 和 MutableCopy的区别 深浅拷贝的区别
- 关于vc++ runtime error解决方法汇总
- Face Detection using OpenCV Haarcascades in Android
- 最新AndroidStudio使用教程
- npoi操作excel导出和合并(二)