UA-17470720-3

Jump to content


Photo
- - - - -

soft delete - sectionActions.willDeleteItem - refresh on return false?

view-controllers actions core-data

  • Please log in to reply
1 reply to this topic

#1 markr

markr

    Sr. Member

  • STV 5.0 Pro
  • PipPipPip
  • 41 posts
Reputation: 5
Good

Posted 27 February 2014 - 10:24 AM

WOOPS - May have found the answer here...http://sensiblecocoa...ddata#entry9521 --- Mark

 

Hi All -

 

I'm still a newbie at this so I'm probably missing something pretty straight forward.  I've got a filterPredicate set (working) that only presents items from Core Data with a delete flag that's equal to false (i.e. not deleted).  And, I've got sectionActions.willDeleteItem getting called in edit mode when the delete button is pressed.

 

In the willDeleteItem code, I'm able to update the delete flag to true.  That will keep the item in Core Data marked as deleted so that it can be sent to the backend later.  However, when I return false from willDeleteItem to prevent the delete action completing, the table view display still shows the deleted item.  As far as I can tell, the SCTableViewController is not refreshing the content and re-applying the filterPredica

 

Is there any way to use willDeleteItem to update the content of the item so a filterPredicate will exclude it (i.e. soft delete) without actually completing the deletion?

 

The alternative I'm looking at now is to use willDeleteItem to create a duplicate item that's marked for deletion and return true to allow the existing Core Data item to be deleted.  However, that seems like a pretty expensive operation for something that's got to be regularly needed and I'm not sure at this point that it won't create other issues...

 

Here's my code:

 

 

    NSPredicate *excludeDeletedObjects = [NSPredicate predicateWithFormat:@"deleteFlag == NO"];
    SCArrayOfObjectsSection *objectsSection = [SCArrayOfObjectsSection sectionWithHeaderTitle:nil
                                                                             entityDefinition:itemDef
                                                                              filterPredicate:excludeDeletedObjects];

...

    objectsSection.sectionActions.willDeleteItem = ^BOOL(SCArrayOfItemsSection *itemsSection, NSObject *item, NSIndexPath *indexPath)
    {
        // change deleteFlag to true to pass in next sync to server
        [item setValue:[NSNumber numberWithBool:YES] forKey:@"deleteFlag"];


        // return false to prevent deletion actual deletion
        return FALSE;
    };

 

Thanks,

Mark


Edited by markr, 27 February 2014 - 11:03 AM.


#2 markr

markr

    Sr. Member

  • STV 5.0 Pro
  • PipPipPip
  • 41 posts
Reputation: 5
Good

Posted 27 February 2014 - 11:07 AM

Hi All -

 

Answered my own question...apologies for the extra post - the answer was at http://sensiblecocoa...ddata#entry9521

 

My updated code is now as follows and works so far...

 

    NSPredicate *excludeDeletedObjects = [NSPredicate predicateWithFormat:@"deleteFlag == NO"];
    SCArrayOfObjectsSection *objectsSection = [SCArrayOfObjectsSection sectionWithHeaderTitle:nil
                                                                             entityDefinition:itemDef
                                                                              filterPredicate:excludeDeletedObjects];

...

    objectsSection.sectionActions.willDeleteItem = ^BOOL(SCArrayOfItemsSection *itemsSection, NSObject *item, NSIndexPath *indexPath)
    {
        // change deleteFlag to true to pass in next sync to server
        [item setValue:[NSNumber numberWithBool:YES] forKey:@"deleteFlag"];

 

        // refresh the view
        [self.tableViewModel reloadBoundValues];
        [self.tableViewModel.tableView reloadData];


        // return false to prevent actual deletion
        return FALSE;
    };







Also tagged with one or more of these keywords: view-controllers, actions, core-data

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users