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