Failed to delete the first row of the table in the iPhone application.

I have an iPhone application that uses TableView to display marked items saved by the user. I have a delete explorer for these items, but I ran into a problem with the very first item in the table. All other items display the Delete button when scrolling, but it does not work for the first line.

I searched and searched for the answer to this question. I would be grateful for your help!

- (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { if([indexPath row] == 0) { return UITableViewCellEditingStyleNone; } return UITableViewCellEditingStyleDelete; } 
+4
source share
1 answer

You should return a UITableViewCellEditingStyleDelete from tableView: editingStyleForRowAtIndexPath: for all rows that should support deletion.

UPDATE
I explained what your code does in some of the added comments, so you can see the problem:

 - (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { if([indexPath row] == 0) { // any row that returns UITableViewCellEditingStyleNone will NOT support delete (in your case, the first row is returning this) return UITableViewCellEditingStyleNone; } // any row that returns UITableViewCellEditingStyleDelete will support delete (in your case, all but the first row is returning this) return UITableViewCellEditingStyleDelete; } 
+2
source

All Articles