Problem with commitEditingStyle - delete cell in table

I have one partition table that contains a partition, and I want to delete the cell summary and delete this cell and remove this cell from the table, as well as delete from the array.

and how to animate it while deleting a cell.

for this code below, but which does not work, please help to do this.

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source [self.reports removeObjectAtIndex:indexPath.row]; [tbl reloadData]; [tbl deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath] withRowAnimation:UITableViewRowAnimationFade]; } } 

After much more R&D, I create new code and successfully executed

 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source [[[self.reports objectAtIndex:indexPath.section] valueForKey:@"events"] removeObjectAtIndex:indexPath.row]; [tbl deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationLeft]; [NSTimer scheduledTimerWithTimeInterval: 0.1 target: self selector: @selector(tableReload) userInfo: nil repeats: NO]; } 

}

 -(void)tableReload{ [tbl reloadData]; } 
+3
iphone xcode uitableview
source share
2 answers

First, you should not Reload table before deleting the row from the table. Secondly, in your case, you have several sections and several lines in this section, I think. So your

 [tbl deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 

will not work.
Removing an object from an array will work. You do not need to delete a row from your table. Just reload the table:

  - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source [self.reports removeObjectAtIndex:indexPath.row]; [tbl reloadData]; } 

But be careful with the correct index number.

+9
source share

You are not zero ending your NSArray, and therefore the row is not removed from your table view.

Next line:

 [tbl deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 

Actually it should be:

 [tbl deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationFade]; 

Note the zero after IndexPath. arrayWithObjects should be a null complete list of objects

+2
source share

All Articles