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
property -
didRemoveSection
property -
sortSections
property -
sectionForSectionIndexTitle
property -
didFinishLoadingCells
property -
didRefresh
property -
didScroll
property -
didEndDragging
property -
didEndDecelerating
property -
shouldBeginEditing
property -
didBeginEditing
property -
shouldEndEditing
property -
didEndEditing
property -
didMoveCell
property
SCArrayOfItemsModel Actions
-
didFetchItemsFromStore
property -
sectionHeaderTitleForItem
property -
sectionHeaderTitles
property -
didComputeSearchResults
property
Miscellaneous
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:
// Objective-C
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];
}
};
// Swift
modelActions.didAddSection =
{
(tableModel, section, sectionIndex) in
// use custom data sorting for the first section in a Core Data SCArrayOfObjectsModel
if let objectsSection = section as? SCArrayOfObjectsSection
{
if sectionIndex==0
{
let oldFetchOptions = objectsSection.dataFetchOptions
objectsSection.dataFetchOptions = SCCoreDataFetchOptions(sortKey: oldFetchOptions.sortKey, sortAscending: false, filterPredicate: oldFetchOptions.filterPredicate)
}
}
}
Declared In
SCModelActions.h
didBeginEditing
Action gets called after the model’s table view has entered editing mode.
@property (nonatomic, copy) SCModelAction_Block didBeginEditing
Discussion
Example:
// Objective-C
modelActions.didBeginEditing = ^(SCTableViewModel *tableModel)
{
NSLog(@"The model has entered editing mode.");
};
// Swift
modelActions.didBeginEditing =
{
(tableModel) in
NSLog("The model has entered editing mode.")
}
Declared In
SCModelActions.h
didComputeSearchResults
Action gets called when SCArrayOfItemsModel has computed the search results for the given searchText.
@property (nonatomic, copy) SCDidComputeSearchResultsAction_Block didComputeSearchResults
Discussion
Use this action is typically used to customize the automatically computed searchResults array.
Example:
// Objective-C
modelActions.didComputeSearchResults = ^NSArray*(SCArrayOfItemsModel *itemsModel, NSString *searchText, NSArray *searchResults)
{
return myCustomSearchResults;
};
// Swift
modelActions.didComputeSearchResults =
{
(itemsModel, searchText, searchResults)->[AnyObject] in
return myCustomSearchResults
}
Declared In
SCModelActions.h
didEndDecelerating
Action gets called after the model’s table view has ended decelerating.
@property (nonatomic, copy) SCModelAction_Block didEndDecelerating
Discussion
Example:
// Objective-C
modelActions.didEndDecelerating = ^(SCTableViewModel *tableModel)
{
NSLog(@"The model's table view has ended decelerating.");
};
// Swift
modelActions.didEndDecelerating =
{
(tableModel) in
NSLog("The model's table view has ended decelerating.")
}
Declared In
SCModelActions.h
didEndDragging
Action gets called after the model’s table view has ended dragging.
@property (nonatomic, copy) SCModelAction_Block didEndDragging
Discussion
Example:
// Objective-C
modelActions.didEndDragging = ^(SCTableViewModel *tableModel)
{
NSLog(@"The model's table view has ended dragging with decelerating=%i.", tableModel.tableView.decelerating);
};
// Swift
modelActions.didEndDragging =
{
(tableModel) in
NSLog("The model's table view has ended dragging with decelerating=%i.", tableModel.tableView.decelerating)
}
Declared In
SCModelActions.h
didEndEditing
Action gets called after the model’s table view has exited editing mode.
@property (nonatomic, copy) SCModelAction_Block didEndEditing
Discussion
Example:
// Objective-C
modelActions.didEndEditing = ^(SCTableViewModel *tableModel)
{
NSLog(@"The model has exited editing mode.");
};
// Swift
modelActions.didEndEditing =
{
(tableModel) in
NSLog("The model has exited editing mode.")
}
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:
// Objective-C
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:NSTextAlignmentCenter];
buttonCell.cellActions.didSelect = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
{
NSLog(@"buttonCell tapped!");
};
[items addObject:buttonCell];
};
// Swift
modelActions.didFetchItemsFromStore =
{
(itemsModel, items) in
// Add a button cell at the end of the fetched items list
let buttonCell = SCTableViewCell(text: "Tap me!", textAlignment: .Center)
buttonCell.cellActions.didSelect =
{
(cell, indexPath) in
NSLog("buttonCell tapped!")
}
items.addObject(buttonCell)
}
Note: This action is only applicable to SCArrayOfItemsModel subclasses, such as SCArrayOfObjectsModel.
Declared In
SCModelActions.h
didFinishLoadingCells
Action gets called as soon as the model’s table view has finished loading all its cells.
@property (nonatomic, copy) SCModelAction_Block didFinishLoadingCells
Discussion
Example:
// Objective-C
modelActions.didFinishLoadingCells = ^(SCTableViewModel *tableModel)
{
NSLog(@"The table view has finished loading cells.");
};
// Swift
modelActions.didFinishLoadingCells =
{
(tableModel) in
NSLog("The table view has finished loading cells.")
}
Declared In
SCModelActions.h
didMoveCell
Action gets called after any of the model’s sections' cells has moved.
@property (nonatomic, copy) SCDidMoveCellAction_Block didMoveCell
Discussion
Example:
// Objective-C
modelActions.didMoveCell = ^(SCTableViewModel *tableModel, SCTableViewCell *cell, NSIndexPath *fromIndexPath, NSIndexPath *toIndexPath)
{
NSLog(@"A cell has been moved from:%@ to:%@.", fromIndexPath, toIndexPath);
};
// Swift
modelActions.didMoveCell =
{
(tableModel, cell, fromIndexPath, toIndexPath) in
NSLog("A cell has been moved from:%@ to:%@.", fromIndexPath, toIndexPath)
}
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:
// Objective-C
modelActions.didRefresh = ^(SCTableViewModel *tableModel)
{
NSLog(@"The model has been refreshed.");
};
// Swift
modelActions.didRefresh =
{
(tableModel) in
NSLog("The model has been refreshed.")
}
Declared In
SCModelActions.h
didRemoveSection
Action gets called as soon as a section has been removed from the model.
@property (nonatomic, copy) SCDidRemoveSectionAction_Block didRemoveSection
Discussion
Example:
// Objective-C
modelActions.didRemoveSection = ^(SCTableViewModel *tableModel, NSUInteger sectionIndex)
{
NSLog(@"Section at index '%i' has been removed.", sectionIndex);
};
// Swift
modelActions.didRemoveSection =
{
(tableModel, sectionIndex) in
NSLog("Section at index '%i' has been removed.", sectionIndex)
}
Declared In
SCModelActions.h
didScroll
Action gets called after the model’s table view has started scrolling.
@property (nonatomic, copy) SCModelAction_Block didScroll
Discussion
Example:
// Objective-C
modelActions.didScroll = ^(SCTableViewModel *tableModel)
{
NSLog(@"The model's table view has started scrolling.");
};
// Swift
modelActions.didScroll =
{
(tableModel) in
NSLog("The model's table view has started scrolling.")
}
Declared In
SCModelActions.h
ownerTableViewModel
The owner table view model of the actions object.
@property (nonatomic, weak) SCTableViewModel *ownerTableViewModel
Discussion
Warning: This property gets set automatically by the framework, you should never set this property manually
Declared In
SCModelActions.h
sectionForSectionIndexTitle
Action gets called to give you a chance to return the index of the section having the given title and section title index.
@property (nonatomic, copy) SCSectionForSectionIndexTitleAction_Block sectionForSectionIndexTitle
Discussion
Example:
// Objective-C
modelActions.sectionForSectionIndexTitle = ^NSInteger(SCTableViewModel *tableModel, NSString *title, NSInteger index)
{
if(index < tableModel.sectionCount)
return index;
// else return the last section index
return tableModel.sectionCount-1;
};
// Swift
modelActions.sectionForSectionIndexTitle =
{
(tableModel, title, index)->NSInteger in
if index < tableModel.sectionCount
{
return index
}
// else return the last section index
return tableModel.sectionCount-1
}
Note: ‘index’ is an index number identifying a section title in the SCTableViewModel’s ‘sectionIndexTitles’ array.
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:
// Objective-C
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];
};
// Swift
modelActions.sectionHeaderTitleForItem =
{
(itemsModel, item, itemIndex)->String! in
let objectName = item.valueForKey("firstName") as! String
// Return first charcter of objectName
return objectName.substringToIndex(advance(objectName.startIndex, 1)).uppercaseString
}
Declared In
SCModelActions.h
sectionHeaderTitles
Implement this action to provide custom sections for SCArrayOfItemsModel.
@property (nonatomic, copy) SCSectionHeaderTitlesAction_Block sectionHeaderTitles
Discussion
Example:
// Objective-C
modelActions.sectionHeaderTitles = ^NSArray*(SCArrayOfItemsModel *itemsModel)
{
return @[@"Section A", @"Section B", @"Section C"];
};
// Swift
modelActions.sectionHeaderTitles =
{
(tableModel)->[AnyObject] in
return ["Section A", "Section B", "Section C"]
}
Declared In
SCModelActions.h
shouldBeginEditing
Action gets called as the model’s table view is about to enter editing mode. Return NO to prevent the table view from entering editing mode, otherwise return YES.
@property (nonatomic, copy) SCConditionalModelAction_Block shouldBeginEditing
Discussion
Example:
// Objective-C
modelActions.shouldBeginEditing = ^BOOL(SCTableViewModel *tableModel)
{
NSLog(@"The model is about to enter editing mode.");
return YES; // allow editing to begin
};
// Swift
modelActions.shouldBeginEditing =
{
(tableModel)->Bool in
NSLog("The model is about to enter editing mode.")
return true // allow editing to begin
}
Declared In
SCModelActions.h
shouldEndEditing
Action gets called as the model’s table view is about to exit editing mode. Return NO to prevent the table view from exiting editing mode, otherwise return YES.
@property (nonatomic, copy) SCConditionalModelAction_Block shouldEndEditing
Discussion
Example:
// Objective-C
modelActions.shouldEndEditing = ^BOOL(SCTableViewModel *tableModel)
{
NSLog(@"The model is about to exit editing mode.");
return YES; // allow editing to end
};
// Swift
modelActions.shouldEndEditing =
{
(tableModel)->Bool in
NSLog("The model is about to exit editing mode.")
return true // allow editing to end
}
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:
// Objective-C
modelActions.sortSections = ^(SCTableViewModel *tableModel, NSMutableArray *sections)
{
// Rearrange the 'sections' mutable array here as you see fit
};
// Swift
modelActions.sortSections =
{
(tableModel, sections) in
// 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