UA-17470720-3

Jump to content


Photo
- - - - -

SCArrayOfObjectsModel Problems


  • Please log in to reply
6 replies to this topic

#1 ozie

ozie

    ¯\_(ツ)_/¯

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

Posted 27 January 2014 - 11:29 PM

Hi guys

 

trying to use SCArrayOfObjectsModel, as i have it load items and build section headers for grouping

When there are NO items for it to list, i can't seem to find a way to add a new item

SCArrayOfObjectsSection *objectsSection = (SCArrayOfObjectsSection *)[self.tableViewModel sectionAtIndex:0];
[objectsSection dispatchEventAddNewItem];

calling something like this is no good since the table is empty there are no sections at any index so calling dispatchEventAddNewItem on nil doesn't work

 

if i use this

NSObject *myObject = [NSEntityDescription insertNewObjectForEntityForName:@"entity" inManagedObjectContext:moContext];
[self.tableViewModel generateSectionsForObject:myObject withDefinition:myDef];

well this loads the view ok.. and i can enter in a new item, but if i decide to click cancel, the item is still added to the dataset even thou items have in the definition - Required..

 

so how do others get around this problem?


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


#2 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 545 posts
  • LocationIreland
Reputation: 137
Popular

Posted 28 January 2014 - 01:08 AM

Hi ozie,

 

This is working for me:

  SCPropertyDefinition *addSongPropertyDefinition = [setlistEntityDefinition propertyDefinitionWithName:@"~addSong"];
    addSongPropertyDefinition.title = @"Add a Song…";
    addSongPropertyDefinition.existsInCreationMode = NO;
    addSongPropertyDefinition.existsInEditingMode = YES;
    addSongPropertyDefinition.existsInNormalMode = NO;
    addSongPropertyDefinition.existsInDetailMode = YES;
    addSongPropertyDefinition.cellActions.willConfigure = ^(SCTableViewCell *cell, NSIndexPath *indexPath) {
        cell.cellEditingStyle = UITableViewCellEditingStyleInsert;
        cell.editable = YES;        
    };
    
    addSongPropertyDefinition.cellActions.didSelect = ^(SCTableViewCell *cell, NSIndexPath *indexPath) {
        SCArrayOfObjectsSection *section = (SCArrayOfObjectsSection*)[cell.ownerTableViewModel sectionAtIndex:kdgSongsSection];
        [section dispatchEventAddNewItem];
    };

 

 

kdgSongsSection is defined as 1 in my case.

 

 

Why is your objectsSection nil? Even with an empty section there will still be a header and a footer.


Cheers,

Dave

www.dgapps.ie

#3 ozie

ozie

    ¯\_(ツ)_/¯

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

Posted 28 January 2014 - 02:27 AM

hey Dave

 

I'm using a SCArrayOfObjectsModel 

i can see your code would work as your must already have a cell to be able to have a didSelect fire.. and since there is a cell there has to be a section

in the SCArrayOfObjectsModel it doesn't work the same, and I'm firing my dispatch event from an action sheet.. when no items load there are no sections for it to use and hence my problem


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


#4 ozie

ozie

    ¯\_(ツ)_/¯

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

Posted 28 January 2014 - 03:09 AM

i have narrowed it down to me adding a placeHolderCell by creating a section when there are no items in the did fetch action.. so now i just need to work out a way to still show a placeholder when its empty


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


#5 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 545 posts
  • LocationIreland
Reputation: 137
Popular

Posted 28 January 2014 - 03:18 AM

Hi ozie,

 

My ~addSong cell is actually in a separate section to the songs section.

 

How are you creating the section in the first place? Even my empty sections have a header and footer.

 

If you are firing the dispatch event from an action sheet is self.tableViewModel the correct tableViewModel?

 

Not sure what else to suggest...

 

Re your placeholder solution, there's the placeholderCell of SCArrayOfObjectSection, but I'm sure you've found that already in the documentation


Cheers,

Dave

www.dgapps.ie

#6 wizgod

wizgod

    I'm what you guys call a User

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

Posted 22 May 2015 - 11:49 AM

Greetings Programs!

 

ozie, did you ever get this sorted? I'm in the same boat: http://sensiblecocoa...tsmodel-is-nil/

 

Wg


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


#7 wizgod

wizgod

    I'm what you guys call a User

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

Posted 22 May 2015 - 01:21 PM

Got it sorted out:

 

tableViewModel.modelActions.didFetchItemsFromStore = {
    (itemsSection, items) in

    var buttonCell = SCTableViewCell(text: "Add Point", textAlignment: NSTextAlignment.Center)
    buttonCell.cellActions.didSelect = {
        (cell, indexPath) in
        
        (cell.ownerSection as! SCArrayOfObjectsSection).dispatchEventAddNewItem()
    }
    
    items.addObject(buttonCell)
}

 

Wg


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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users