Edit:
Ok, give it a try. :) This should definitely work, but it takes a lot of effort ...
You will need to accurately track changes in the data source (add, delete, update) and call the appropriate methods in TableVC.
The data source source will need to be provided with the following delegate methods:
- (void)dataControllerWillUpdateData; - (void)dataControllerDidRemoveObjectAtIndexPath:(NSIndexPath *)indexPath; - (void)dataControllerDidAddObjectAtIndexPath:(NSIndexPath *)indexPath; - (void)dataControllerDidUpdateObjectAtIndexPath:(NSIndexPath *)indexPath; - (void)dataControllerDidUpdateData;
Then you change the implementation of tableVC as follows:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) {
So, if the user deletes the cell, your data source must determine what other objects are affected, create a change list (be careful to calculate the correct index columns), call dataControllerWillUpdateData , call the corresponding methods above for each changed object, and finally call dataControllerDidUpdateData .
Of course, you can also consider using CoreData in your project. This may require some work to configure everything, but as a result you will get all of the above and much more βfor freeβ. Personally, I tend to use it for almost every project that includes dynamic tables. It has so many advantages that it is most worth the effort.
source share