nurnachman
nurnachman

Reputation: 4565

How to remove a cell from a UITableView at runtime?

I want to remove a specific cell from a UITableView

I found deleteRowsAtIndexPaths:withRowAnimation:

I tried to change the cell.frame to 0,0,0,0

I tried to .hidden = YES it

nothing works for me.

Any ideas?

Thank you!

Upvotes: 1

Views: 4723

Answers (2)

Abhishek
Abhishek

Reputation: 2253

Use this method to remove the cell from your table view and hand to hand remove the same objects from your array by which you are showing data on tableview.

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

   if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source

        [yourArray removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];

       } 
       [tableView reloadData];
}

Hope this will help you..

Upvotes: 0

Ian L
Ian L

Reputation: 5591

Try adding the begin and end calls for editing:

[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:deletePaths withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];

Alternatively, if you are working with an underlying data source, remove the object from the datasource and call [tableView reloadData];

Upvotes: 1

Related Questions