0

I have implemented the tableView:editActionsForRowAtIndexPath: function, however i experience intermittently the indexPath passed to this function is nil. When i try to access indexPath.row , its get a value 18446744073709551615.

I am querying for the object in the array I use to build the table. and getting the crash --[__NSArrayM objectAtIndex:]: index 18446744073709551615 beyond bounds [0 .. 1]'

There was a case where I was reloading my table using [table reloadData] an editAction call then would get passed a nil indexPath, however this is still intermittently happening.

Is there any way i can enforce the correct indexPath to be passed to tableView:editActionsForRowAtIndexPath:

Nirav Kotecha
  • 2,493
  • 1
  • 12
  • 26
New_coder
  • 103
  • 2
  • 10

1 Answers1

0

You have to implement this - (void)tableView:(UITableView *)tableView commitEditingStyle method where data array need to be adjusted.

For details look at this article Inserting and Deleting Rows and Sections

You can handle this by removing the item corresponding to the row from data array at first and then sending deleteRowsAtIndexPaths:withRowAnimation: to the table view.

Try to insert below lines of code inside - (void)tableView:(UITableView *)tableView commitEditingStyle method:

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

      // remove item from array at first 
      [dataArray removeObjectAtIndex:indexPath.row];

      // then delete table row from tableview
      [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
   }
}

Hope it will work!

Shamim Hossain
  • 1,690
  • 12
  • 21