UA-17470720-3

Jump to content


Photo
- - - - -

SCSelectionModel & Section Headers


  • Please log in to reply
3 replies to this topic

#1 Andrew_P

Andrew_P

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 22 posts
Reputation: 5
Good

Posted 05 January 2014 - 04:58 PM

Hello All!

 

   I've been trying to get my head around the idea of a SCPropertyType that is a Selection, which will allow me to separate all the items into various sections and also have an addNewItemCell. 

 

Here is the code declaring the definition

    SCPropertyDefinition *typeDef = [entity propertyDefinitionWithName:kTypeAttribute];
    typeDef.type = SCPropertyTypeSelection;
    
    SCSelectionAttributes *selectionAttributes = [SCSelectionAttributes attributesWithItems:@[@"One", @"Two", @"Three", @"Four", @"Five"] allowMultipleSelection:NO allowNoSelection:YES];
    typeDef.attributes = selectionAttributes;

To obtain section headers i've implemented the following..

 

    typeDef.cellActions.detailTableViewModel = ^SCTableViewModel*(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        SCSelectionModel *selectionModel = [[SCSelectionModel alloc] initWithTableView:nil];
        
        selectionModel.modelActions.sectionHeaderTitleForItem = ^NSString*(SCArrayOfItemsModel *itemsModel, NSObject *item, NSUInteger itemIndex)
        {
            if (itemIndex > 2)
                return @"Section 2";
            else
                return @"Section 1";
        };
};

Which gives a detailViewController with items broken into two sections. 

 

However, i've had no luck being able to have an addNewItemCell. I attempted to assign it during the addSection modelAction block like so

        selectionModel.modelActions.didAddSection = ^(SCTableViewModel *tableModel, SCTableViewSection *section, NSUInteger sectionIndex)
        {
            if (sectionIndex == 1)
            {
                NSLog(@"Attempting to add addNewCell");
                
                SCArrayOfObjectsSection *s = (SCArrayOfObjectsSection *)section;
                s.addNewItemCell = [SCTableViewCell cellWithText:@"Add"];
                s.addNewItemCellExistsInNormalMode = YES;
                s.addNewItemCellExistsInEditingMode = YES;
            }
        };

But the various methods i've attempted never show the addNewItemCell, i've managed to add a cell which adds a new item using dispatchEventAddNewItem however the cell that dispatched the event then becomes selected.

 

If anyone has any ideas that would be great! 

 

Many Thanks



#2 ozie

ozie

    ¯\_(ツ)_/¯

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

Posted 06 January 2014 - 12:21 AM

Hey Andrew

you can break items up into sections in two ways

1.. 

SCEntityDefinition *myDef = [SCEntityDefinition
  definitionWithEntityName:@"entry"
  propertyNamesString:@"Details:(title);Actions:(date,time)"];

2..

SCEntityDefinition *myDef = [SCEntityDefinition definitionWithEntityName:@"entry"
                                                            managedObjectContext:moContext
                                                           propertyNamesString:@"title;date;time"];
 
SCPropertyGroup *g1 = [SCPropertyGroup groupWithHeaderTitle:@"section 1" footerTitle:nil propertyNames:@[@"title"]];
SCPropertyGroup *g2 = [SCPropertyGroup groupWithHeaderTitle:@"section 2" footerTitle:nil propertyNames:@[@"date",@"time"]];
 
[examDef.propertyGroups addGroup:g1];
[examDef.propertyGroups addGroup:g2];

 

as for adding a add new cell

    SCArrayOfObjectsSection *objectsSection = [SCArrayOfObjectsSection
                                               sectionWithHeaderTitle:.........
    objectsSection.allowAddingItems = YES;

    SCTableViewCell *addCell = [SCTableViewCell cellWithText:NSLocalizedString(@"Add New", nil)];
    addCell.imageView.image = [UIImage imageNamed:@"greenAdd"];
    
    
    objectsSection.addNewItemCell = addCell;
    objectsSection.addNewItemCellExistsInNormalMode = YES;

Edited by ozie, 06 January 2014 - 12:21 AM.

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


#3 Andrew_P

Andrew_P

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 22 posts
Reputation: 5
Good

Posted 06 January 2014 - 06:35 PM

Ozie, thanks for your reply! I probably didn't explain myself exactly as i intended. The actual issue is essentially trying to format the auto generated detail controller where the user can select one of the items.  If i created a simple selectionCell like this 

 

    SCTableViewSection *section = [SCTableViewSection section];
    
    SCSelectionCell *selectionCell = [SCSelectionCell cellWithText:@"Test" boundObject:nil selectedIndexPropertyName:nil items:@[@"Item 1", @"Item 2", @"Item 3"]];
    
    selectionCell.allowAddingItems = YES;
    selectionCell.addNewItemCell = [SCTableViewCell cellWithText:@"Add New Item"];
    
    [section addCell:selectionCell];
    
    [self.tableViewModel addSection:section];

The detailViewController would have all the items in a single section. 

 

Ideally what i'd like to do is have the selectable items in different sections with an extra cell that allows a newItem to be added.

 

Hopefully that makes more sense!



#4 ozie

ozie

    ¯\_(ツ)_/¯

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

Posted 06 January 2014 - 09:03 PM

you would have to build your own detailviewcontroller and pass that into the cell as an action.. that way you can customise it to the way you want..

cellActions.detailViewController = ^UIViewController*(SCTableViewCell *cell, NSIndexPath *indexPath) 

 

there is no option for the scselectioncell to place items into sections, as normally a selection object is from a simple list

 

might be able to use this one too.. not sure which one is best or easier

cellActions.detailTableViewModel = ^SCTableViewModel*(SCTableViewCell *cell, NSIndexPath *indexPath)

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