-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewRowAction *deleteRoWAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@" 删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {//title可自已定义
//这里面写button点击之后的事件
[self.dataArray removeObjectAtIndex:indexPath.row];//这里的dataArray是可变数组,滑动删除的时候,需要删除数组中的元素
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}];
deleteRoWAction.backgroundColor = [UIColor redColor];
UITableViewRowAction *test = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"设为已读" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {//title可自已定义
}];
test.backgroundColor = [UIColor grayColor];
return @[deleteRoWAction,test];//最后返回这俩个RowAction 的数组
}
本文介绍如何在iOS应用中实现UITableView的滑动删除功能,包括定制删除按钮的行为及样式。通过具体代码示例展示了如何设置删除操作及响应处理。
623

被折叠的 条评论
为什么被折叠?



