- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView1 cellForRowAtIndexPath:indexPath];
UITableViewRowAction *flagAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
[tableData removeObjectAtIndex:indexPath.row];
NSLog(@"indexpath %ld",indexPath.row);
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}];
return @[ flagAction];
}
答案 0 :(得分:3)
您可以向表格添加滑动手势并删除行,如下所示。
- (void)viewDidLoad {
UISwipeGestureRecognizer *gestureDeleteRow = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(cellSwipe:)];
gestureDeleteRow.direction = UISwipeGestureRecognizerDirectionRight;
[tableView addGestureRecognizer:gestureDeleteRow];
}
//Swipe Handler Method
-(void)cellSwipe:(UISwipeGestureRecognizer *)gesture
{
CGPoint location = [gesture locationInView:tableView];
NSIndexPath *swipedIndexPath = [tableView indexPathForRowAtPoint:location];
//Delete Row…
[ARRAY removeObjectAtIndex: swipedIndexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:swipedIndexPath, nil] withRowAnimation:UITableViewRowAnimationLeft];
}
答案 1 :(得分:0)
使用动画滑动表格单元格检查此代码 Github Code