iOS tableView editCell 删除Cell 置顶Cell NSIndexPath写法
2016-08-26 16:12
411 查看
//正常码tableView 加如下方法:
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath
*)indexPath{
//删除按钮
UITableViewRowAction *deleteRowAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDefault
title:@"删除"
handler:^(UITableViewRowAction *
_Nonnull action,
NSIndexPath * _Nonnull indexPath){
[_dataArray
removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationNone];
}];
//置顶按钮
UITableViewRowAction *toTopRowAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDefault
title:@"置顶"
handler:^(UITableViewRowAction *
_Nonnull action,
NSIndexPath * _Nonnull indexPath){
NSLog(@"置顶");
[_dataArray
exchangeObjectAtIndex:indexPath.row
withObjectAtIndex:0];
NSIndexPath *sourceIndexPath = [NSIndexPath
indexPathForRow:indexPath.row
inSection:0];
NSIndexPath *destinationIndexPath = [NSIndexPath
indexPathForRow:0
inSection:0];
[tableView moveRowAtIndexPath:sourceIndexPath
toIndexPath:destinationIndexPath];
tableView.editing =
NO;
}];
toTopRowAction.backgroundColor = [UIColor
orangeColor];
//其他按钮
UITableViewRowAction *otherRowAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDefault
title:@"其他"
handler:^(UITableViewRowAction *
_Nonnull action,
NSIndexPath * _Nonnull indexPath){
NSLog(@"其他");
[self.tableView
reloadData];
}];
otherRowAction.backgroundColor = [UIColor
lightGrayColor];
//返回按钮数组
return
@[deleteRowAction, toTopRowAction, otherRowAction];
}
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath
*)indexPath{
//删除按钮
UITableViewRowAction *deleteRowAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDefault
title:@"删除"
handler:^(UITableViewRowAction *
_Nonnull action,
NSIndexPath * _Nonnull indexPath){
[_dataArray
removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationNone];
}];
//置顶按钮
UITableViewRowAction *toTopRowAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDefault
title:@"置顶"
handler:^(UITableViewRowAction *
_Nonnull action,
NSIndexPath * _Nonnull indexPath){
NSLog(@"置顶");
[_dataArray
exchangeObjectAtIndex:indexPath.row
withObjectAtIndex:0];
NSIndexPath *sourceIndexPath = [NSIndexPath
indexPathForRow:indexPath.row
inSection:0];
NSIndexPath *destinationIndexPath = [NSIndexPath
indexPathForRow:0
inSection:0];
[tableView moveRowAtIndexPath:sourceIndexPath
toIndexPath:destinationIndexPath];
tableView.editing =
NO;
}];
toTopRowAction.backgroundColor = [UIColor
orangeColor];
//其他按钮
UITableViewRowAction *otherRowAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDefault
title:@"其他"
handler:^(UITableViewRowAction *
_Nonnull action,
NSIndexPath * _Nonnull indexPath){
NSLog(@"其他");
[self.tableView
reloadData];
}];
otherRowAction.backgroundColor = [UIColor
lightGrayColor];
//返回按钮数组
return
@[deleteRowAction, toTopRowAction, otherRowAction];
}
相关文章推荐
- 关于tableview的知识总结,cell左划出现删除、置顶按钮
- iOS tableView 如何禁止滑动手势删除,只允许在编辑模式下进行删除Cell
- tableview cell 左划删除/重命名/修改/置顶
- iOS 使用cell的删除功能,实现tableview的代理
- (原创)iOS tableview系统左滑删除 左滑置顶 自定义左滑事件功能 输入框弹出
- IOS 构造和使用TableView(基于storyboard) (四)启用Table Viewcell的滑动删除
- iOS开发tableview 的cell 侧滑删除
- IOS TableView 左滑动删除Cell方法
- ios tableview cell 侧滑删除
- IOS TableView Cell重用机制及TableView常用Code
- IOS开发 tableview中cell的用法
- ios中Tableview的两个获得重用cell方法的区别?(兼容iPhone5.0之前的版本)
- [iOS] 延时加载TableView中Cell中的图片
- ios tableView那些事 (十五)用故事模式自定义cell
- IOS TableView Cell重用机制及TableView
- ios tableView那些事(四)tableView添加标题,头尾和改变cell的宽度
- ios tableView那些事 (十四) 获取 tableview 每个cell 的坐标点
- IOS TableView中Cell的重用reuse机制分析
- ios tableView那些事 (十六) UITableView中Cell重用机制导致内容重复解决方法