SCModelActions Class Reference
Inherits from | NSObject |
Declared in | SCModelActions.h |
Overview
This class hosts a set of model action blocks. Once an action is set to a desired code block, it will execute the block as soon as the action occurs.
Tasks
Actions
-
didAddSection
Action gets called as soon as a section has been added to the model.
property -
sortSections
Action gets called to give you a chance to provide custom section sorting.
property -
didRefresh
Action gets called as soon as the model has refreshed its contents after returning from a pull-to-refresh operation.
property
SCArrayOfItemsModel Actions
-
didFetchItemsFromStore
Action gets called as soon as the model has retrieved its items from their data store.
property -
sectionHeaderTitleForItem
Action gets called when SCArrayOfItemsModel requests a section header title for each of its items.
property
Miscellaneous
-
ownerTableViewModel
The owner table view model of the actions object.
property -
– setActionsTo:overrideExisting:
Method assigns all the actions of another ‘SCModelActions’ class to the current one.
Properties
didAddSection
Action gets called as soon as a section has been added to the model.
@property (nonatomic, copy) SCDidAddSectionAction_Block didAddSection
Discussion
This action is typically used to customize automatically generated sections (e.g.: sections generated by SCArrayOfObjectsModel).
Example:
modelActions.didAddSection = ^(SCTableViewModel *tableModel, SCTableViewSection *section, NSUInteger sectionIndex)
{
// use custom data sorting for the first section in a Core Data SCArrayOfObjectsModel
if(sectionIndex==0 && [section isKindOfClass:[SCArrayOfObjectsSection class]])
{
SCArrayOfObjectsSection *objectsSection = (SCArrayOfObjectsSection *)section;
SCCoreDataFetchOptions *oldFetchOptions = (SCCoreDataFetchOptions *)objectsSection.dataFetchOptions;
objectsSection.dataFetchOptions = [SCCoreDataFetchOptions optionsWithSortKey:oldFetchOptions.sortKey sortAscending:FALSE filterPredicate:oldFetchOptions.filterPredicate];
}
};
Declared In
SCModelActions.h
didFetchItemsFromStore
Action gets called as soon as the model has retrieved its items from their data store.
@property (nonatomic, copy) SCDidFetchModelItemsAction_Block didFetchItemsFromStore
Discussion
This action is typically used to customize the ‘items’ array after it has been fetched from the data store. Items can be added, removed, or rearranged. The added items can either be objects that are suppored by the data store, or normal SCTableViewCell (or subclass) objects.
Example:
modelActions.didFetchItemsFromStore = ^(SCArrayOfItemsModel *itemsModel, NSMutableArray *items)
{
// Add a button cell at the end of the fetched items list
SCTableViewCell *buttonCell = [SCTableViewCell cellWithText:@"Tap me!" textAlignment:UITextAlignmentCenter];
buttonCell.cellActions.didSelect = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
{
NSLog(@"buttonCell tapped!");
};
[items addObject:buttonCell];
};
Note: This action is only applicable to SCArrayOfItemsModel subclasses, such as SCArrayOfObjectsModel.
Declared In
SCModelActions.h
didRefresh
Action gets called as soon as the model has refreshed its contents after returning from a pull-to-refresh operation.
@property (nonatomic, copy) SCModelAction_Block didRefresh
Discussion
Example:
modelActions.didRefresh = ^(SCTableViewModel *tableModel)
{
NSLog(@"The model has been refreshed.");
};
Declared In
SCModelActions.h
ownerTableViewModel
The owner table view model of the actions object.
@property (nonatomic, unsafe_unretained) SCTableViewModel *ownerTableViewModel
Discussion
Warning: This property gets set automatically by the framework, you should never set this property manually
Declared In
SCModelActions.h
sectionHeaderTitleForItem
Action gets called when SCArrayOfItemsModel requests a section header title for each of its items.
@property (nonatomic, copy) SCSectionHeaderTitleForItemAction_Block sectionHeaderTitleForItem
Discussion
Use this action to control how the automatically generated sections are created. In the following example, a new section will be created for each group of items sharing the same first letter (i.e.: items will be grouped alphabetically).
Example:
modelActions.sectionHeaderTitleForItem = ^NSString*(SCArrayOfItemsModel *itemsModel, NSObject *item, NSUInteger itemIndex)
{
NSString *objectName = (NSString *)[item valueForKey:@"firstName"];
// Return first charcter of objectName
return [[objectName substringToIndex:1] uppercaseString];
};
Declared In
SCModelActions.h
sortSections
Action gets called to give you a chance to provide custom section sorting.
@property (nonatomic, copy) SCSortSectionsAction_Block sortSections
Discussion
Example:
modelActions.sortSections = ^(SCTableViewModel *tableModel, NSMutableArray *sections)
{
// Rearrange the 'sections' mutable array here as you see fit
};
Note: To have the model automatically sort its sections alphabetically, simply set its ‘autoSortSections’ property to TRUE.
Declared In
SCModelActions.h
Instance Methods
setActionsTo:overrideExisting:
Method assigns all the actions of another ‘SCModelActions’ class to the current one.
- (void)setActionsTo:(SCModelActions *)actions overrideExisting:(BOOL)override
Parameters
- actions
The source ‘SCModelActions’ class.
- override
Set to TRUE to override any existing actions, otherwise set to FALSE.
Declared In
SCModelActions.h