UA-17470720-3

Jump to content


Photo
- - - - -

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

wfreitag

    Starting Out

  • STV Lite
  • Pip
  • 1 posts
Reputation: 0
Neutral

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"
                                                              managedObjectContext:context
                                                               propertyNamesString:@":(name);Address:(address1,address2,city,state,zip);Geolocation:(lat,lng)"];
    
    SCEntityDefinition *merchantDef = [SCEntityDefinition definitionWithEntityName:@"Merchant"
                                                              managedObjectContext:context
                                                               propertyNamesString:@":(name);:(categories,locations)"];
    
    // 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.

 

Warren







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