不得不说apple太机智,让我们编程的时候变的方便简洁
好了言归正传,其实右侧滑动多项操作我们只需要实现delegate协议中的- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
方法就好了,它是返回一个UITableViewRowAction数组,
类UITableViewRowAction描述UITableViewRowAction对象定义了一个单一的行动,现在当用户刷水平表中的行。在一个可编辑的表,执行水平滑动在一行显示一个默认按钮删除行。这个类允许您定义一个或多个自定义动作显示表中给定的一行。这个类的每个实例代表一个单一动作执行,包括文本、格式信息和行为对应的按钮,
#pragma mark --多标签操作
- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewRowAction *delete = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
//当点击删除执行块中的内容
[self presentViewController:[self getAlert:@"删除" leeter:@"您确定要删除这条数据吗?" alertText:nil index:indexPath] animated:true completion:nil];
UITableViewRowAction *insert = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"修改" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
[self presentViewController:[self getAlert:@"修改信息" leeter:@"请输入您要删除的信息" alertText:@"请输入您要修改的名称" index:indexPath] animated:true completion:nil];
}];
insert.backgroundColor = [UIColor greenColor];
//返回这两个rowAction到数组
return @[insert,delete];
}