您的位置:首页 > 其它

tableviewcell添加多个按钮删除事件

2016-02-15 11:30 281 查看
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{

if (editingStyle ==
UITableViewCellEditingStyleDelete) {
[_dataArray
removeObjectAtIndex:indexPath.row];

[tableView deleteRowsAtIndexPaths:[NSArray
arrayWithObjects:indexPath, nil]
withRowAnimation:UITableViewRowAnimationNone];
}
}
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath
*)indexPath
{

//
添加一个删除按钮

UITableViewRowAction *deleteRowAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDefault
title:@"Delete"
handler:^(UITableViewRowAction *action,
NSIndexPath *indexPath){
[_dataArray
removeObjectAtIndex:indexPath.row];

[tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];
}];

//
删除一个置顶按钮

UITableViewRowAction *topRowAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDefault
title:@"Top"
handler:^(UITableViewRowAction *action,
NSIndexPath *indexPath){

NSLog(@"The action to top");
}];
topRowAction.backgroundColor = [UIColor
blueColor];

//
添加一个更多按钮

UITableViewRowAction *moreRowAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDefault
title:@"More"
handler:^(UITableViewRowAction *action,
NSIndexPath *indexPath){

NSLog(@"The action to more");
}];

moreRowAction.backgroundEffect = [UIBlurEffect
effectWithStyle:UIBlurEffectStyleDark];

//
将设置好的按钮放到数组中返回

return @[deleteRowAction, topRowAction, moreRowAction];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: