Inherits from NSObject
Declared in SCSectionActions.h

Overview

This class hosts a set of section action blocks. Once an action is set to a desired code block, it will execute the block as soon as the action occurs.

Tasks

Section Actions

  •   didAddToModel

    Action gets called right after the section has been added to a model.

    property

Detail Model Actions

  •   detailModelCreated

    Action gets called right after the section’s detail model is created, before configuration is set or any sections are added.

    property
  •   detailModelConfigured

    Action gets called after the section’s detail model is fully configured, including the addition of all automatically generated sections.

    property
  •   detailModelWillPresent

    Action gets called when the section’s detail model is about to be presented in its own view controller.

    property
  •   detailModelDidPresent

    Action gets called when the section’s detail model has been presented in its own view controller.

    property
  •   detailModelWillDismiss

    Action gets called when the section’s detail model’s view controller is about to be dismissed.

    property
  •   detailModelDidDismiss

    Action gets called when the section’s detail model’s view controller has been dismissed.

    property
  •   detailViewControllerForRowAtIndexPath

    Action gets called to give you the chance to return a custom detail view controller for the section.

    property
  •   detailTableViewModelForRowAtIndexPath

    Action gets called to give you the chance to return a custom detail model for the section’s detail view controller.

    property

SCArrayOfItemsSection Actions

  •   cellForRowAtIndexPath

    Action gets called to give you the chance to return a custom cell for the section’s item, instead of the automatically generated standard SCTableViewCell.

    property
  •   reuseIdentifierForRowAtIndexPath

    In case more than one type of custom cell is returned in cellForRowAtIndexPath, this action gets called to give you the chance to return a custom cell reuse identifier for each different type.

    property
  •   customHeightForRowAtIndexPath

    Action gets called to give you the chance to return a custom cell height for each of the section’s cells, instead of the automatically calculated cell height.

    property
  •   didFetchItemsFromStore

    Action gets called as soon as the section has retrieved its items from their data store.

    property
  •   fetchItemsFromStoreFailed

    Action gets called if the section fails to retrieve its items from their data store.

    property
  •   didCreateItem

    Action gets called as soon as the section has created a new item to be used in its add new item detail view (which usually apprears right after the user taps the section’s Add button).

    property
  •   willInsertItem

    Action gets called right before a newly created item is inserted into the section.

    property
  •   didInsertItem

    Action gets called as soon as a new item has been added to the section.

    property
  •   willUpdateItem

    Action gets called right before an existing item is updated.

    property
  •   didUpdateItem

    Action gets called as soon as an existing item has been updated.

    property
  •   willDeleteItem

    Action gets called right before an existing item is deleted.

    property
  •   didDeleteItem

    Action gets called as soon as an existing item has been deleted.

    property
  •   didAddSpecialCells

    Action gets called after the section has retrieved its items from their data store, and the framework has automatically added any needed special cells (e.g.: placeholder cell, load more cell, etc.) to the items array.

    property

Miscellaneous

Properties

cellForRowAtIndexPath

Action gets called to give you the chance to return a custom cell for the section’s item, instead of the automatically generated standard SCTableViewCell.

@property (nonatomic, copy) SCCellForRowAtIndexPathAction_Block cellForRowAtIndexPath

Return Value

The custom cell. Must only be of type SCCustomCell or subclass. Note: returning nil ignores the implementation of this action.

Example:

sectionActions.cellForRowAtIndexPath = ^SCCustomCell*(SCArrayOfItemsSection *itemsSection, NSIndexPath *indexPath)
{
    // '1' and '2' are the tags of the labels corresponding to 
    // the firstName and lastName object properties
    NSString *bindingsString = @"1:firstName;2:lastName";

    SCCustomCell *customCell = [SCCustomCell cellWithText:nil objectBindingsString:bindingsString nibName:@"MyCustomCell"];

    return customCell;
};

Discussion

Warning: If more than one type of custom cell is returned (e.g.: depending on the indexPath), then you must also use the reuseIdentifierForRowAtIndexPath action to return a unique reuse id for each different cell you return. Otherwise, there is no need to set the reuseIdentifierForRowAtIndexPath action.

Note: This action is only applicable to sections that generate detail views, such as SCArrayOfObjectsSection.

Declared In

SCSectionActions.h

customHeightForRowAtIndexPath

Action gets called to give you the chance to return a custom cell height for each of the section’s cells, instead of the automatically calculated cell height.

@property (nonatomic, copy) SCCustomHeightForRowAtIndexPathAction_Block customHeightForRowAtIndexPath

Return Value

The custom cell height. Note: returning -1 ignores the implementation of this action and will have the framework automatically calculate the cell height.

Example:

sectionActions.customHeightForRowAtIndexPath = ^CGFloat(SCArrayOfItemsSection *itemsSection, NSIndexPath *indexPath)
{
    CGFloat cellHeight;
    if(indexPath.row % 2)
        cellHeight = 44;
    else
        cellHeight = 60;

    return cellHeight;
};

Discussion

Note: Implementing this action only makes sense in situations where you have a huge number of cells. In these cases, providing the height directly drastically improves performance, versus having the framework automatically calculate the height for each single cell.

See Also

Declared In

SCSectionActions.h

detailModelConfigured

Action gets called after the section’s detail model is fully configured, including the addition of all automatically generated sections.

@property (nonatomic, copy) SCDetailModelSectionAction_Block detailModelConfigured

Discussion

This action is typically used to add additional custom sections, or modify the already existing automatically generated ones.

Example:

sectionActions.detailModelConfigured = ^(SCTableViewSection *section, SCTableViewModel *detailModel, NSIndexPath *indexPath)
{
    SCTableViewSection *customSection = [SCTableViewSection section];
    SCCustomCell *customCell = [SCCustomCell cellWithText:@"Custom Cell"];
    [customSection addCell:customCell];

    [detailModel addSection:customSection];
};

Note: In general, it is easier (and more recommended) to add your custom sections and cells using the data definitions, instead of using this action to do so. For more information, please refer to SCDataDefinition and SCCustomPropertyDefinition.

Note: This action is only applicable to sections that generate detail views, such as SCArrayOfObjectsSection.

Warning: In the case where the detail model is not associated with an existing row (such as the case when ‘SCArrayOfObjectsSection’ creates a new item), indexPath.row will be set to NSNotFound. This is a good way to test if the detail model was generated for a new item or an already existing one.

Declared In

SCSectionActions.h

detailModelCreated

Action gets called right after the section’s detail model is created, before configuration is set or any sections are added.

@property (nonatomic, copy) SCDetailModelSectionAction_Block detailModelCreated

Discussion

This action is typically used to initially configure the detail model (like set a custom tag for example). Most of the model’s settings can also be configure in the detailModelConfigured action.

Example:

sectionActions.detailModelCreated = ^(SCTableViewSection *section, SCTableViewModel *detailModel, NSIndexPath *indexPath)
{
    detailModel.tag = 100;
};

Note: This action is only applicable to sections that generate detail views, such as SCArrayOfObjectsSection.

Warning: In the case where the detail model is not associated with an existing row (such as the case when ‘SCArrayOfObjectsSection’ creates a new item), indexPath.row will be set to NSNotFound. This is a good way to test if the detail model was generated for a new item or an already existing one.

Declared In

SCSectionActions.h

detailModelDidDismiss

Action gets called when the section’s detail model’s view controller has been dismissed.

@property (nonatomic, copy) SCDetailModelSectionAction_Block detailModelDidDismiss

Discussion

Example:

sectionActions.detailModelDidDismiss = ^(SCTableViewSection *section, SCTableViewModel *detailModel, NSIndexPath *indexPath)
{
    NSLog(@"Detail model has been dismissed.");
};

Note: This action is only applicable to sections that generate detail views, such as SCArrayOfObjectsSection.

Warning: In the case where the detail model is not associated with an existing row (such as the case when ‘SCArrayOfObjectsSection’ creates a new item), indexPath.row will be set to NSNotFound. This is a good way to test if the detail model was generated for a new item or an already existing one.

Declared In

SCSectionActions.h

detailModelDidPresent

Action gets called when the section’s detail model has been presented in its own view controller.

@property (nonatomic, copy) SCDetailModelSectionAction_Block detailModelDidPresent

Discussion

Example:

sectionActions.detailModelDidPresent = ^(SCTableViewSection *section, SCTableViewModel *detailModel, NSIndexPath *indexPath)
{
    NSLog(@"Detail model has been presented.");
};

Note: This action is only applicable to sections that generate detail views, such as SCArrayOfObjectsSection.

Warning: In the case where the detail model is not associated with an existing row (such as the case when ‘SCArrayOfObjectsSection’ creates a new item), indexPath.row will be set to NSNotFound. This is a good way to test if the detail model was generated for a new item or an already existing one.

Declared In

SCSectionActions.h

detailModelWillDismiss

Action gets called when the section’s detail model’s view controller is about to be dismissed.

@property (nonatomic, copy) SCDetailModelSectionAction_Block detailModelWillDismiss

Discussion

Example:

sectionActions.detailModelWillDismiss = ^(SCTableViewSection *section, SCTableViewModel *detailModel, NSIndexPath *indexPath)
{
    NSLog(@"Detail model will be dismissed.");
};

Note: This action is only applicable to sections that generate detail views, such as SCArrayOfObjectsSection.

Warning: In the case where the detail model is not associated with an existing row (such as the case when ‘SCArrayOfObjectsSection’ creates a new item), indexPath.row will be set to NSNotFound. This is a good way to test if the detail model was generated for a new item or an already existing one.

Declared In

SCSectionActions.h

detailModelWillPresent

Action gets called when the section’s detail model is about to be presented in its own view controller.

@property (nonatomic, copy) SCDetailModelSectionAction_Block detailModelWillPresent

Discussion

This action is typically used to further customize the detail model’s view controller.

Example:

sectionActions.detailModelWillPresent = ^(SCTableViewSection *section, SCTableViewModel *detailModel, NSIndexPath *indexPath)
{
    detailModel.viewController.title = @"My custom title";
};

Note: This action is only applicable to sections that generate detail views, such as SCArrayOfObjectsSection.

Warning: In the case where the detail model is not associated with an existing row (such as the case when ‘SCArrayOfObjectsSection’ creates a new item), indexPath.row will be set to NSNotFound. This is a good way to test if the detail model was generated for a new item or an already existing one.

Declared In

SCSectionActions.h

detailTableViewModelForRowAtIndexPath

Action gets called to give you the chance to return a custom detail model for the section’s detail view controller.

@property (nonatomic, copy) SCDetailTableViewModelForRowAtIndexPathAction_Block detailTableViewModelForRowAtIndexPath

Return Value

The custom detail model. The returned detail model should not be associated with any table views, as the framework will automatically handle this on your behalf. Note: returning nil ignores the implementation of this action.

Example:

sectionActions.detailTableViewModel = ^SCTableViewModel*(SCTableViewSection *section, NSIndexPath *indexPath)
{
    SCTableViewModel *detailModel = myCustomModel;

    return detailModel;
};

Discussion

This action is typically used to provide your own custom detail model, instead of the one automatically generated by the section.

Note: It is much more common to use the detailViewController action instead, assigning the custom model in the custom view controller’s viewDidLoad method.

Note: This action is only applicable to sections that generate detail views, such as SCArrayOfObjectsSection.

Declared In

SCSectionActions.h

detailViewControllerForRowAtIndexPath

Action gets called to give you the chance to return a custom detail view controller for the section.

@property (nonatomic, copy) SCDetailViewControllerForRowAtIndexPathAction_Block detailViewControllerForRowAtIndexPath

Return Value

The custom view controller. Must only be of type SCViewController or SCTableViewController. Note: returning nil ignores the implementation of this action.

Example:

sectionActions.detailViewController = ^UIViewController*(SCTableViewSection *section, NSIndexPath *indexPath)
{
    MyCustomViewController *customVC = [[MyCustomViewController alloc] initWithNib:@"MyCustomViewController" bundle:nil];

    return customVC;
};

Discussion

This action is typically used to provide your own custom detail view controller, instead of the one automatically generated by the section.

Note: This action is only applicable to sections that generate detail views, such as SCArrayOfObjectsSection.

Declared In

SCSectionActions.h

didAddSpecialCells

Action gets called after the section has retrieved its items from their data store, and the framework has automatically added any needed special cells (e.g.: placeholder cell, load more cell, etc.) to the items array.

@property (nonatomic, copy) SCDidAddSpecialCellsAction_Block didAddSpecialCells

Discussion

This action is typically used to customize the ‘items’ array after it has been fetched from the data store and the special cells added to it.

Example:

sectionActions.didAddSpecialCells = ^(SCArrayOfItemsSection *itemsSection, NSMutableArray *items)
{
    // Add a button cell at the end of the 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 SCArrayOfItemsSection subclasses, such as SCArrayOfObjectsSection.

Declared In

SCSectionActions.h

didAddToModel

Action gets called right after the section has been added to a model.

@property (nonatomic, copy) SCDidAddToModelSectionAction_Block didAddToModel

Discussion

This action is typically used to get hold of the section at data definition time and perform any additional configuration.

Example:

myArrayOfObjectsAttributes.expandContentInCurrentView = YES;
myArrayOfObjectsAttributes.expandedContentSectionActions.didAddToModel = ^(SCTableViewSection *section, NSUInteger sectionIndex)
{
    // set all expanded cells to a different background color
    section.cellActions.willDisplay = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        cell.backgroundColor = [UIColor yellowColor];
    };
};

Declared In

SCSectionActions.h

didCreateItem

Action gets called as soon as the section has created a new item to be used in its add new item detail view (which usually apprears right after the user taps the section’s Add button).

@property (nonatomic, copy) SCSectionItemDidCreateAction_Block didCreateItem

Discussion

This action is typically used to customize the newly created item before the new item detail view is displayed.

Example:

sectionActions.didCreateItem = ^(SCArrayOfItemsSection *itemsSection, NSObject *item)
{
    // Set an initial value for startDate
    [item setValue:[NSDate date] forKey:@"startDate"];
};

Note: This action is only applicable to SCArrayOfItemsSection subclasses, such as SCArrayOfObjectsSection.

Declared In

SCSectionActions.h

didDeleteItem

Action gets called as soon as an existing item has been deleted.

@property (nonatomic, copy) SCSectionItemDidDeleteAction_Block didDeleteItem

Discussion

This action is typically used to provide custom functionality after an item has been deleted.

Example:

sectionActions.didDeleteItem = ^(SCArrayOfItemsSection *itemsSection, NSIndexPath *indexPath)
{
    NSLog(@"Item at indexPath: %@ has been deleted.", indexPath);
};

Note: This action is only applicable to SCArrayOfItemsSection subclasses, such as SCArrayOfObjectsSection.

Declared In

SCSectionActions.h

didFetchItemsFromStore

Action gets called as soon as the section has retrieved its items from their data store.

@property (nonatomic, copy) SCDidFetchSectionItemsAction_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:

sectionActions.didFetchItemsFromStore = ^(SCArrayOfItemsSection *itemsSection, NSMutableArray *items)
{
    // Add a button cell at the end of the 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 SCArrayOfItemsSection subclasses, such as SCArrayOfObjectsSection.

Declared In

SCSectionActions.h

didInsertItem

Action gets called as soon as a new item has been added to the section.

@property (nonatomic, copy) SCSectionItemDidInsertAction_Block didInsertItem

Discussion

This action is typically used to provide custom functionality after a new item has been added.

Example:

sectionActions.didInsertItem = ^(SCArrayOfItemsSection *itemsSection, NSObject *item, NSIndexPath *indexPath)
{
    NSLog(@"New item inserted at indexPath: %@", indexPath);
};

Note: This action is only applicable to SCArrayOfItemsSection subclasses, such as SCArrayOfObjectsSection.

Declared In

SCSectionActions.h

didUpdateItem

Action gets called as soon as an existing item has been updated.

@property (nonatomic, copy) SCSectionItemDidUpdateAction_Block didUpdateItem

Discussion

This action is typically used to provide custom functionality after an item has been updated.

Example:

sectionActions.didUpdateItem = ^(SCArrayOfItemsSection *itemsSection, NSObject *item, NSIndexPath *indexPath)
{
    NSLog(@"Item updated at indexPath: %@", indexPath);
};

Note: This action is only applicable to SCArrayOfItemsSection subclasses, such as SCArrayOfObjectsSection.

Declared In

SCSectionActions.h

fetchItemsFromStoreFailed

Action gets called if the section fails to retrieve its items from their data store.

@property (nonatomic, copy) SCFetchSectionItemsFailedAction_Block fetchItemsFromStoreFailed

Discussion

This action is typically used when the section is bound to a web service and you want to give the user feedback that their web service was not reachable.

Example:

 sectionActions.fetchItemsFromStoreFailed = ^(SCArrayOfItemsSection *itemsSection, NSError *error)
 {
      NSLog(@"Failed retrieving section items with error: %@", error);
 };

Note: This action is only applicable to SCArrayOfItemsSection subclasses, such as SCArrayOfObjectsSection.

Declared In

SCSectionActions.h

reuseIdentifierForRowAtIndexPath

In case more than one type of custom cell is returned in cellForRowAtIndexPath, this action gets called to give you the chance to return a custom cell reuse identifier for each different type.

@property (nonatomic, copy) SCReuseIdForRowAtIndexPathAction_Block reuseIdentifierForRowAtIndexPath

Return Value

An NSString containing the custom cell reuse identifier.

Example:

sectionActions.cellForRowAtIndexPath = ^SCCustomCell*(SCArrayOfItemsSection *itemsSection, NSIndexPath *indexPath)
{
    SCCustomCell *customCell;
    if(indexPath.row % 2)
        customCell = [[MyCustomEvenCell alloc] init];
    else
        customCell = [[MyCustomOddCell alloc] init];

    return customCell;
};

sectionActions.reuseIdentifierForRowAtIndexPath = ^NSString*(SCArrayOfItemsSection *itemsSection, NSIndexPath *indexPath)
{
    NSString *reuseId;
    if(indexPath.row % 2)
        reuseId = @"EvenCell";
    else
        reuseId = @"OddCell";

    return reuseId;
};

Discussion

Note: You only need to set this action if more than one type of custom cell is returned in cellForRowAtIndexPath.

Note: This action is only applicable to sections that generate detail views, such as SCArrayOfObjectsSection.

Declared In

SCSectionActions.h

willDeleteItem

Action gets called right before an existing item is deleted.

@property (nonatomic, copy) SCSectionItemWillDeleteAction_Block willDeleteItem

Discussion

This action is typically used to provide you with a chance to override the item delete operation by returning FALSE.

Example:

sectionActions.willDeleteItem = ^BOOL(SCArrayOfItemsSection *itemsSection, NSObject *item, NSIndexPath *indexPath)
{
    BOOL deleteItem;

    if(myCondition)
        deleteItem = TRUE;
    else
        deleteItem = FALSE;

    return deleteItem;
};

Note: This action is only applicable to SCArrayOfItemsSection subclasses, such as SCArrayOfObjectsSection.

Declared In

SCSectionActions.h

willInsertItem

Action gets called right before a newly created item is inserted into the section.

@property (nonatomic, copy) SCSectionItemWillInsertAction_Block willInsertItem

Discussion

This action is typically used to customize the newly created item before it’s inserted. Furthermore, returning FALSE gives you the chance to discard adding the new item altogether.

Example:

sectionActions.willInsertItem = ^BOOL(SCArrayOfItemsSection *itemsSection, NSObject *item, SCTableViewModel *itemModel)
{
    // Set a default description if no description is set
    if(![item valueForKey:@"description"])
        [item setValue:@"My default description" forKey:@"description"];

    // Accept insert
    return TRUE;
};

Note: This action is only applicable to SCArrayOfItemsSection subclasses, such as SCArrayOfObjectsSection.

Declared In

SCSectionActions.h

willUpdateItem

Action gets called right before an existing item is updated.

@property (nonatomic, copy) SCSectionItemWillUpdateAction_Block willUpdateItem

Discussion

This action is typically used to customize the user’s changes before the item is updated. Furthermore, returning FALSE gives you the chance to discard updating the item altogether.

Example:

sectionActions.willUpdateItem = ^BOOL(SCArrayOfItemsSection *itemsSection, NSObject *item, NSIndexPath *indexPath, SCTableViewModel *itemModel)
{
    // Set a default description if no description is set
    if(![item valueForKey:@"description"])
        [item setValue:@"My default description" forKey:@"description"];

    // Accept update
    return TRUE;
};

Note: This action is only applicable to SCArrayOfItemsSection subclasses, such as SCArrayOfObjectsSection.

Declared In

SCSectionActions.h

Instance Methods

setActionsTo:overrideExisting:

Method assigns all the actions of another ‘SCSectionActions’ class to the current one.

- (void)setActionsTo:(SCSectionActions *)actions overrideExisting:(BOOL)override

Parameters

actions

The source ‘SCSectionActions’ class.

override

Set to TRUE to override any existing actions, otherwise set to FALSE.

Declared In

SCSectionActions.h