怎样给嵌套在UIScrollView内的UItableView添加侧滑功能?

iOS给独立的UITableview中添加侧滑功能是很简单的,UITableView的代理方法中已经集成了侧滑删除的功能,只要实现以下的方法就能增加侧滑删除。

//先要设Cell可编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
 return YES;
}
//定义编辑样式
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 
return UITableViewCellEditingStyleDelete;
}
//修改编辑按钮文字
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
 return @"删除";
}
//设置进入编辑状态时,Cell不会缩进
- (BOOL)tableView: (UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
 return NO;
}
//点击删除
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
 //在这里实现删除操作 //删除数据,和删除动画 
  [self.myDataArr removeObjectAtIndex:deleteRow];
  [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:deleteRow inSection:0]] withRowAnimation:UITableViewRowAnimationTop];
}

但是当UItableView嵌套在UIScrollView中时,由于手势冲突,会发现上述方法失效啦,这时可以使用以下方法:

//使用UITableViewRowAction来实现侧滑
-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(nonnull NSIndexPath *)indexPath{
    UITableViewRowAction *actionName = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"yourAction" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
        /* your code here*/
    }];
    return @[collectionRowAction];
}

你可能感兴趣的:(怎样给嵌套在UIScrollView内的UItableView添加侧滑功能?)