ios TableView那些事(三十一)UITableViewController ios8 删除时添加多个按钮
2016-11-24 15:10
561 查看
iOS 新的属性
typedef
NS_ENUM(NSInteger, UITableViewRowActionStyle) {
UITableViewRowActionStyleDefault =0,
UITableViewRowActionStyleDestructive =UITableViewRowActionStyleDefault,
UITableViewRowActionStyleNormal
} NS_ENUM_AVAILABLE_IOS(8_0);
NS_CLASS_AVAILABLE_IOS(8_0)@interface UITableViewRowAction :NSObject <NSCopying>
+ (instancetype)rowActionWithStyle:(UITableViewRowActionStyle)style title:(NSString *)title handler:(void (^)(UITableViewRowAction
*action, NSIndexPath *indexPath))handler;
/////////////////下面实现相关代码////////////////////////////
(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
returnYES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath
*)indexPath{
if (editingStyle ==UITableViewCellEditingStyleDelete) {
[self.dataSourceremoveObjectAtIndex:indexPath.row];
[self.tableViewdeleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
//设置删除按钮
UITableViewRowAction *deleteRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDestructivetitle:@"删除"handler:^(UITableViewRowAction
*action,NSIndexPath *indexPath) {
[self.dataSourceremoveObjectAtIndex:indexPath.row];
[self.tableViewdeleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];
}];
//设置收藏按钮
UITableViewRowAction *collectRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDefaulttitle:@"收藏"handler:^(UITableViewRowAction
*action,NSIndexPath *indexPath) {
collectRowAction.backgroundColor = [UIColorgreenColor];
UIAlertView *alertView = [[UIAlertViewalloc]initWithTitle:@"收藏"message:@"收藏成功"delegate:selfcancelButtonTitle:@"确定"otherButtonTitles:nil,nil];
[alertView show];
}];
//设置置顶按钮
UITableViewRowAction *topRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDefaulttitle:@"置顶"handler:^(UITableViewRowAction
*action,NSIndexPath *indexPath) {
[self.dataSourceexchangeObjectAtIndex:indexPath.rowwithObjectAtIndex:0];
NSIndexPath *firstIndexPath = [NSIndexPathindexPathForRow:0inSection:indexPath.section];
[tableView moveRowAtIndexPath:indexPathtoIndexPath:firstIndexPath];
}];
collectRowAction.backgroundEffect = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleLight];
topRowAction.backgroundColor = [UIColorblueColor];
collectRowAction.backgroundColor = [UIColorgrayColor];
return
@[deleteRowAction,collectRowAction,topRowAction];
}
typedef
NS_ENUM(NSInteger, UITableViewRowActionStyle) {
UITableViewRowActionStyleDefault =0,
UITableViewRowActionStyleDestructive =UITableViewRowActionStyleDefault,
UITableViewRowActionStyleNormal
} NS_ENUM_AVAILABLE_IOS(8_0);
NS_CLASS_AVAILABLE_IOS(8_0)@interface UITableViewRowAction :NSObject <NSCopying>
+ (instancetype)rowActionWithStyle:(UITableViewRowActionStyle)style title:(NSString *)title handler:(void (^)(UITableViewRowAction
*action, NSIndexPath *indexPath))handler;
/////////////////下面实现相关代码////////////////////////////
(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
returnYES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath
*)indexPath{
if (editingStyle ==UITableViewCellEditingStyleDelete) {
[self.dataSourceremoveObjectAtIndex:indexPath.row];
[self.tableViewdeleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
//设置删除按钮
UITableViewRowAction *deleteRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDestructivetitle:@"删除"handler:^(UITableViewRowAction
*action,NSIndexPath *indexPath) {
[self.dataSourceremoveObjectAtIndex:indexPath.row];
[self.tableViewdeleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];
}];
//设置收藏按钮
UITableViewRowAction *collectRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDefaulttitle:@"收藏"handler:^(UITableViewRowAction
*action,NSIndexPath *indexPath) {
collectRowAction.backgroundColor = [UIColorgreenColor];
UIAlertView *alertView = [[UIAlertViewalloc]initWithTitle:@"收藏"message:@"收藏成功"delegate:selfcancelButtonTitle:@"确定"otherButtonTitles:nil,nil];
[alertView show];
}];
//设置置顶按钮
UITableViewRowAction *topRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDefaulttitle:@"置顶"handler:^(UITableViewRowAction
*action,NSIndexPath *indexPath) {
[self.dataSourceexchangeObjectAtIndex:indexPath.rowwithObjectAtIndex:0];
NSIndexPath *firstIndexPath = [NSIndexPathindexPathForRow:0inSection:indexPath.section];
[tableView moveRowAtIndexPath:indexPathtoIndexPath:firstIndexPath];
}];
collectRowAction.backgroundEffect = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleLight];
topRowAction.backgroundColor = [UIColorblueColor];
collectRowAction.backgroundColor = [UIColorgrayColor];
return
@[deleteRowAction,collectRowAction,topRowAction];
}
相关文章推荐
- ios TableView那些事(三十一)UITableViewController ios8 删除时添加多个按钮
- ios tableView那些事 (十三) 给 tableview 添加索引
- ios tableView那些事(三)给tableView添加些图片
- ios 如何让TableView加入横向滑动出现删除按钮的功能
- ios tableView那些事(三)给tableView添加些图片
- IOS_修改TableView的删除按钮的文本
- iOS tableView删除,添加,排序方法实现
- ios tableView那些事 (七) 给tableView添加响应事件
- iOS 在tableView上添加button导致按钮没有点击效果和不能滑动的 zhuang
- ios tableView那些事 (十一) 让 tableview 不可滚动或屏蔽掉
- 0819-TableView(tableVeiw控件的代理)(tableView单组 lol数据展示)(tableView-汽车品牌logo 右侧a-z)(KVC)(tableView - 添加删除按钮出现)(自定义代理delegate)(内存)
- ios tableView那些事 (十一) 让 tableview 不可滚动或屏蔽掉
- ios tableView那些事 (九) tableview的删除
- iOS-tableView底部按钮的添加
- ios 如何让TableView加入横向滑动出现删除按钮的功能
- IOS_修改TableView的删除按钮的文本
- tableview添加删除按钮
- ios tableView那些事 (七) 给tableView添加响应事件
- iOS 在tableView上添加button导致按钮没有点击效果和不能滑动的问题
- ios tableView那些事 (九) tableview的删除