Delete a UITableView row by click on custom UIButton

后端 未结 7 1005
梦谈多话
梦谈多话 2020-12-22 04:16

Basically I want to delete row on click event of a button which is a part of that row.
I can not use commit editing style because i want to perform unsubscribe and dele

7条回答
  •  囚心锁ツ
    2020-12-22 04:42

    Tapping a row and deleting it should be possible in a way like this: In your didSelectRowAtIndexPath you can implement the following:

    [myArrayWithSubscriptions removeObjectAtIndex:indexPath.row]; 
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    

    If you want to only tap the UIButton to delete use this code in the action behing the UIButton.

    CGPoint point;
    NSIndexPath *indexPath;
    point = [sender.center locationInView:tableView];
    indexPath = [tableView indexPathForRowAtPoint:point];
    [myArrayWithSubscriptions removeObjectAtIndex:indexPath.row]; 
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    

    That way you have the indexPath from the cell that had its UIButton tapped, and should be able to continue to delete it. I'm typing this on the go and will check this code later for any typos.

提交回复
热议问题