Jump to content

- - - - -

Trapping the "Done" action on nested edit screens

actions view-controllers sections core-data data-stores

  • Please log in to reply
No replies to this topic

#1 wfreitag


    Starting Out

  • STV Lite
  • Pip
  • 1 posts
Reputation: 0

Posted 21 April 2014 - 02:41 PM

Hi All,


I'm working on some simple edit screens for a Core Data model. STV makes it simple to have nested edit screens for one-to-many relations, but I can't figure out how to trap the "Done" button action for one of these nested edit screens.


e.g. I have an edit screen for "Merchant", which has a one-to-many relation with "MerchantLocation".


- (void)viewDidLoad
    [super viewDidLoad];
    [self setTitle:@"Merchants"];
    [self setNavigationBarType:SCNavigationBarTypeAddEditRight];
    NSManagedObjectContext *context = [[AppDelegate sharedDelegate] managedObjectContext];

    SCEntityDefinition *locationDef = [SCEntityDefinition definitionWithEntityName:@"MerchantLocation"
    SCEntityDefinition *merchantDef = [SCEntityDefinition definitionWithEntityName:@"Merchant"
    // Merchant Location editor
    SCPropertyDefinition *merchantLocationPropertyDef = [merchantDef propertyDefinitionWithName:@"locations"];
    [merchantLocationPropertyDef setType:SCPropertyTypeArrayOfObjects];
    [[merchantLocationPropertyDef cellActions] setDetailModelWillDismiss:^(SCTableViewCell *cell, NSIndexPath *indexPath, SCTableViewModel *detailModel)
        // This gets called for EVERY dismissal, so how do I check to see if it was closed with the "Done" button???
    SCArrayOfObjectsAttributes *merchantLocationAttributes = [SCArrayOfObjectsAttributes attributesWithObjectDefinition:locationDef allowAddingItems:YES allowDeletingItems:YES allowMovingItems:NO];
    [merchantLocationAttributes setPlaceholderuiElement:[SCTableViewCell cellWithText:@"No locations" textAlignment:NSTextAlignmentCenter]];
    [merchantLocationPropertyDef setAttributes:merchantLocationAttributes];
    // Merchant section definition
    SCArrayOfObjectsSection *merchantSection = [SCArrayOfObjectsSection sectionWithHeaderTitle:nil entityDefinition:merchantDef];
    [merchantSection setAddButtonItem:[self addButton]];
    [merchantSection setPlaceholderCell:[SCTableViewCell cellWithText:@"No merchants" textAlignment:NSTextAlignmentCenter]];
    [[self tableViewModel] addSection:merchantSection];

I've gotten as far as being able to trap the DetailModelWillDismiss action for the nested Location screen, but I can't determine HOW it was dismissed (whether the user canceled or pressed Done). This is critical for me because I want to run the Geolocator to derive the lat/long for every Location record that's added or edited.


Thanks for any help/suggestions.



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

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users