UA-17470720-3

Jump to content


Photo
- - - - -

How to create an item, and never save it till the DONE button is pressed


  • Please log in to reply
8 replies to this topic

#1 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 12 January 2016 - 09:33 PM

So I have a problem that if the New Item view is open and the user presses the HOME button on the device, the new item is saved, even when required fields are still blank

 

    SCEntityDefinition *myDef = [SCEntityDefinition definitionWithEntityName:@"Entity" managedObjectContext:moContext propertyNamesString:@"title"];
    
    
    SCPropertyDefinition *titleDef = [myDef propertyDefinitionWithName:@"title"];
    titleDef.required = YES;
    
    Entity *mEntity = [NSEntityDescription
                      insertNewObjectForEntityForName:@"Entity"
                      inManagedObjectContext:moContext];
    
    SCTableViewController *detailVC = [[SCTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
    detailVC.navigationBarType = SCNavigationBarTypeEditRight;
    detailVC.autoDisableNavigationButtonsUntilViewAppears = YES;
    
    [detailVC.tableViewModel generateSectionsForObject:mEntity withDefinition:myDef newObject:YES]; //does not seem to do anything setting YES or NO here
    
    
    [detailVC.tableViewModel generateSectionsForObject:course withDefinition:courseDef newObject:NO];
    detailVC.preferredContentSize = CGSizeMake(500, 400);
    detailVC.modalPresentationStyle = UIModalPresentationFormSheet;
    detailVC.navigationBarType = SCNavigationBarTypeDoneRightCancelLeft;
    detailVC.title = @"New";
    
    detailVC.tableViewModel.cellActions.willDisplay = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        if (indexPath.row == 0) {
            SCTextFieldCell *tfc = (SCTextFieldCell*)cell;
            tfc.textField.placeholder = @"Title";
            tfc.textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
        }
    };
    
    
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:detailVC];
    nav.modalPresentationStyle = UIModalPresentationFormSheet;
    
    [self.navigationController presentViewController:nav  animated:YES completion:nil];

 

newObject:NO or newObject:YES does not seem to do anything..

Even without pressing the HOME device button, if the users taps the CANCEL button the item is still added to the database

 

Oz


Edited by ozie, 12 January 2016 - 09:38 PM.

  • Adjuramum likes this

P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#2 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 12 January 2016 - 11:48 PM

i think i have solved it by using

    SCDataStore *store = [myDef generateCompatibleDataStore];
    [detailVC.tableViewModel generateSectionsForObject:[store createNewObject] withDataStore:store newObject:YES];

 

using this code, pressing the HOME device button does not create a new item

 

 

Problem now is, that pressing DONE does not add the new entered into into the data entity


P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#3 wizgod

wizgod

    I'm what you guys call a User

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 575 posts
  • LocationThe Grid
Reputation: 149
Popular

Posted 13 January 2016 - 12:46 AM

Greetings Program!

 

Since STV is automatically doing it in SCDataStore with the notifications (http://sensiblecocoa...atabase/?p=9232), perhaps removing the notifications would do? Or maybe overriding commitData in SCCoreDataStore?

 

// Register with UIApplication notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(commitData) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(commitData) name:UIApplicationWillTerminateNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil];

 

Wg


P.S. I love Swift... talk Swift.. Never too old school to learn yet another programming language. LOL! ;-)


#4 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 13 January 2016 - 12:53 AM

so far i have finally found ONE action that will trigger:)

detailVC.actions.doneButtonTapped = ^BOOL(SCTableViewController *viewController)

 

so in there i am getting access to the data object.. just working on how to make it save the uninsertedobject


P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#5 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 13 January 2016 - 01:42 AM

got it all working now


P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#6 wizgod

wizgod

    I'm what you guys call a User

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 575 posts
  • LocationThe Grid
Reputation: 149
Popular

Posted 13 January 2016 - 05:21 AM

Watcha do?

Wgt

P.S. I love Swift... talk Swift.. Never too old school to learn yet another programming language. LOL! ;-)


#7 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 13 January 2016 - 06:30 AM

Hi Ozie,

 

Returning to your very first problem: STV actually checks with Core Data first before saving the new object. Are you sure you have these fields marked as required in your Core Data model? (uncheck 'optional' field)



#8 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 13 January 2016 - 03:12 PM

I re-wrote it all.. seems

Entity *mEntity = [NSEntityDescription
                      insertNewObjectForEntityForName:@"Entity"
                      inManagedObjectContext:moContext];

 

inserts it.. so i used SCDataStore instead to create one and have it all working now nicely 


  • Tarek likes this

P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#9 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 14 January 2016 - 12:44 AM

bugger.. after even more testing I now see that if the user taps CANCEL a new empty entity is added to the database

 

just when i thought it was working.. i found another way blank empty entities are added to the database


P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users