I have inherited an Objective-C code base with a nasty bug where a view controller has a tableview that is seemingly exiting edit mode.
Items are dragged from a view that is above the table and dropped onto the table, which adds them to the backing data store. When the items are dragged onto the table, reloadData is used to refresh the table with the added items. As a matter of fact, reloadData is used a lot sprinkled in the code which bothers me a bit since the table could be moving into edit and non-edit mode via various means.
The code sets the table view into edit mode when a button (labeled Edit) is pressed using the following code
[_tableView setEditing:YES animated:YES];
and when the button is pressed again (labeled Done), the table view is told to exit edit mode using
[_tableView setEditing:NO animated:NO];
While the table is in edit mode, rows can be reordered and deleted. When a row is deleted it is removed from the backing data store and
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
is called to update the table and when there are no more rows in the backing data store, reloadData is called on the table (although I am not sure why since the rows was just deleted from the table with the line above. The problem is that I can add then remove rows from the table view the first time just fine. After that, I drag items to the table view to build the list again. I put the table in edit mode and remove the first row. Once the row gets deleted (with the code directly above) and reloadData is called, the table exits edit mode, meaning that the red circles and reorder buttons go away and the table is out of edit mode.
I guess the bottom line is that the code isn't the best, it feels like spaghetti to me. I had an idea that I would like to observe isEditing of the UITableView instance to see when it is being set to NO. I may try that next to see if I can pinpoint when the tableview is being taken out of edit mode and what may be causing that to happen.
Any ideas why this might be happening would be greatly appreciated.