tableView滑动删除、置顶等

iOS8自带方法自定义按钮背景。实现此代理即可。会覆盖系统自带的删除按钮。做记录。

#pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {

// 添加一个删除按钮
UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {

NSLog(@"点击了删除");
self.tableView.editing =! self.tableView.editing;

}];

// 删除一个置顶按钮
UITableViewRowAction *topRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"置顶" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {

NSLog(@"点击了置顶");

}];

topRowAction.backgroundColor = [UIColor blueColor];

// 添加一个更多按钮
UITableViewRowAction *moreRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"更多" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {

NSLog(@"点击了更多");

}];

moreRowAction.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];

// 将设置好的按钮放到数组中返回
return @[deleteRowAction, topRowAction, moreRowAction];

}

你可能感兴趣的:(tableView滑动删除、置顶等)