iOS开发cell--滑动手势显示按钮
2016-03-01 09:23
537 查看
// 主要代码
#warning iOS8 -
#pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 添加一个删除按钮
UITableViewRowAction *deleteRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"点击了删除");
// 1. 更新数据
[_allDataArray removeObjectAtIndex:indexPath.row];
// 2. 更新UI
[tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];
}];
// 删除一个置顶按钮
UITableViewRowAction *topRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDefault title:@"置顶"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"点击了置顶");
// 1. 更新数据
[_allDataArray exchangeObjectAtIndex:indexPath.row withObjectAtIndex:0];
// 2. 更新UI
NSIndexPath *firstIndexPath = [NSIndexPath indexPathForRow:0inSection:indexPath.section];
[tableView moveRowAtIndexPath:indexPathtoIndexPath:firstIndexPath];
}];
topRowAction.backgroundColor = [UIColor blueColor];
// 添加一个更多按钮
UITableViewRowAction *moreRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleNormal title:@"更多"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"点击了更多");
[tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
}];
moreRowAction.backgroundEffect = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleDark];
// 将设置好的按钮放到数组中返回
return @[deleteRowAction, topRowAction, moreRowAction];
}
递归方法要尽量少使用,另外栈的大小也有一定的限制,如果过多的递归,容易导致stack overflow
#warning iOS8 -
#pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 添加一个删除按钮
UITableViewRowAction *deleteRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"点击了删除");
// 1. 更新数据
[_allDataArray removeObjectAtIndex:indexPath.row];
// 2. 更新UI
[tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];
}];
// 删除一个置顶按钮
UITableViewRowAction *topRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDefault title:@"置顶"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"点击了置顶");
// 1. 更新数据
[_allDataArray exchangeObjectAtIndex:indexPath.row withObjectAtIndex:0];
// 2. 更新UI
NSIndexPath *firstIndexPath = [NSIndexPath indexPathForRow:0inSection:indexPath.section];
[tableView moveRowAtIndexPath:indexPathtoIndexPath:firstIndexPath];
}];
topRowAction.backgroundColor = [UIColor blueColor];
// 添加一个更多按钮
UITableViewRowAction *moreRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleNormal title:@"更多"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"点击了更多");
[tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
}];
moreRowAction.backgroundEffect = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleDark];
// 将设置好的按钮放到数组中返回
return @[deleteRowAction, topRowAction, moreRowAction];
}
递归方法要尽量少使用,另外栈的大小也有一定的限制,如果过多的递归,容易导致stack overflow
相关文章推荐
- iOS开发中的几种设计模式以及各自的优点
- iOS手动内存管理之对象持有对象可能存在的内存泄露问题
- 苹果开发者中心中在provisioning profiles中type为UniversalDistribution和Distribution,两者有什么区别?
- IOS的模态窗口(modal)
- kidd风的IOS开发日志之IOS常用的IOS第三方资源
- ios开发中获取window的方法
- iOS NSClassFromString,NSSelectorFromString,isKingO
- 仿陌陌的ios客户端+服务端源码
- IOS 透明过度层渐变色
- ios NSURLSession 教程,工作流程等
- 安装Cocoapods,以及其中出现的问题
- iOS8 定位
- ios tableview section的运用
- ios 触摸事件
- IOS学习 ModalViewController模态视图的创建 两视图间用代理方式<传值>
- iOS 沙盒
- 【iOS9系列】- CoreSportlight内容索引的使用
- iOS-地图开发 Plist文件设置权限
- iOS-layoutSubvies和drawRect何时调用
- iOS中block介绍(三)揭开神秘面纱(上)