SCCellActions

@interface SCCellActions : NSObject

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

See

SCSectionActions, SCModelActions.

Actions

  • Action gets called before the cell gets automatically styled using the provided theme.

    This action is typically used to set a custom themeStyle for the cell that is defined in the model’s theme file.

    Example:

    // Objective-C
    cellActions.willStyle = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        cell.themeStyle = @"MyCustomStyle";
    };
    
    // Swift
    cellActions.willStyle =
    {
        (cell, indexPath) in
    
        cell.themeStyle = "MyCustomStyle"
    }
    

    See

    SCTheme

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellAction_Block willStyle;
  • Action gets called before the cell is configured.

    This action is typically used to set any attribute that will affect the cell’s configuration and layout.

    Example:

    // Objective-C
    cellActions.willConfigure = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    };
    
    // Swift
    cellActions.willConfigure =
    {
        (cell, indexPath) in
    
        cell.selectionStyle = UITableViewCellSelectionStyleNone
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellAction_Block willConfigure;
  • Action gets called after the cell has laid out all its subviews.

    This action is typically used to change the subviews’ layout.

    Example:

    // Objective-C
    cellActions.didLayoutSubviews = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        cell.textLabel.frame = CGRectMake(40, 20, 100, 40);
    };
    
    // Swift
    cellActions.didLayoutSubviews =
    {
        (cell, indexPath) in
    
        cell.textLabel.frame = CGRectMake(40, 20, 100, 40)
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellAction_Block didLayoutSubviews;
  • Action gets called before the cell is displayed.

    This action is typically used to set any attributes that will affect how the cell is displayed.

    Example:

    // Objective-C
    cellActions.willDisplay = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        cell.backgroundColor = [UIColor yellowColor];
    };
    
    // Swift
    cellActions.willDisplay =
    {
        (cell, indexPath) in
    
        cell.backgroundColor = UIColor.yellowColor()
    }
    

    Note

    Changing cell properties that influence its layout (such as the cell’s height) cannot be set here, and must be set in the willConfigure action instead.

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellAction_Block willDisplay;
  • Action gets called after the cell has been displayed and the table view has stopped scrolling.

    This action is typically used to load any cell content that is too expensive to load in willDisplay, such as retrieving data from a web service. This guarantees smooth and uninterrupted scrolling of the table view.

    Example:

    // Objective-C
    cellActions.lazyLoad = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        cell.imageView.image = [self retrieveImageForRowAtIndexPath:indexPath];
    };
    
    // Swift
    cellActions.lazyLoad =
    {
        (cell, indexPath) in
    
        cell.imageView.image = self.retrieveImageForRowAtIndexPath(indexPath)
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellAction_Block lazyLoad;
  • Action gets called when the cell is about to be selected.

    Example:

    // Objective-C
    cellActions.willSelect = ^BOOL(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        NSLog(@"Cell at indexPath:%@ is about to be selected.", indexPath);
    
        return TRUE;
    };
    
    // Swift
    cellActions.willSelect =
    {
        (cell, indexPath)->Bool in
    
        NSLog("Cell at indexPath:%@ is about to be selected.", indexPath)
    
        return true
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCBOOLReturnCellAction_Block willSelect;

    Return Value

    Return FALSE to prevent selection, otherwise return TRUE.

  • Action gets called when the cell has been selected.

    Example:

    // Objective-C
    cellActions.didSelect = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        NSLog(@"Cell at indexPath:%@ has been selected.", indexPath);
    };
    
    // Swift
    cellActions.didSelect =
    {
        (cell, indexPath) in
    
        NSLog("Cell at indexPath:%@ has been selected.", indexPath)
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellAction_Block didSelect;
  • Action gets called when the cell is about to be deselected.

    Example:

    // Objective-C
    cellActions.willDeselect = ^BOOL(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        NSLog(@"Cell at indexPath:%@ is about to be deselected.", indexPath);
    
        return TRUE;
    };
    
    // Swift
    cellActions.willDeselect =
    {
        (cell, indexPath)->Bool in
    
        NSLog("Cell at indexPath:%@ is about to be deselected.", indexPath)
    
        return true
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCBOOLReturnCellAction_Block willDeselect;

    Return Value

    Return FALSE to prevent deselection, otherwise return TRUE.

  • Action gets called when the cell has been deselected.

    Example:

    // Objective-C
    cellActions.didDeselect = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        NSLog(@"Cell at indexPath:%@ has been selected.", indexPath);
    };
    
    // Swift
    cellActions.didDeselect =
    {
        (cell, indexPath) in
    
        NSLog("Cell at indexPath:%@ has been selected.", indexPath)
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellAction_Block didDeselect;
  • Action gives you the opportunity to provide your own custom cell editing style.

    Example:

    // Objective-C
    cellActions.customEditingStyle = ^UITableViewCellEditingStyle(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        // Prevent swipe-to-delete when not in editing mode.
    
        if(cell.ownerTableViewModel.tableView.editing)
            return UITableViewCellEditingStyleDelete;
        //else
        return UITableViewCellEditingStyleNone;
    };
    
    // Swift
    cellActions.customEditingStyle =
    {
        (cell, indexPath)->UITableViewCellEditingStyle in
    
        // Prevent swipe-to-delete when not in editing mode.
    
        if(cell.ownerTableViewModel.tableView.editing)
        {
            return UITableViewCellEditingStyleDelete;
        }
        //else
        return UITableViewCellEditingStyleNone;
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellCustomEditingStyleAction_Block customEditingStyle;

    Return Value

    Return a valid UITableViewCellEditingStyle value.

  • Action gets called to provide custom edit action buttons that appear when the user swipes the cell horizontally.

    Use this action when you want to provide custom edit actions for your cell. When the user swipes horizontally, the table view moves the cell content aside to reveal your actions. Tapping one of the action buttons executes the handler block stored with the action object.

    Warning

    Only available in iOS 8 and later.

    Example:

    // Objective-C
    cellActions.editActions = ^NSArray*(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        UITableViewRowAction *customButton = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Button" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
        {
            NSLog(@"Custom edit action button tapped!");
    
            [cell.ownerTableViewModel.tableView setEditing:NO]; // collapse the cell back after completing custom edit action
        }];
        customButton.backgroundColor = [UIColor greenColor]; //arbitrary color
    
        UITableViewRowAction *deleteButton = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
        {
            if([cell.ownerSection isKindOfClass:[SCArrayOfItemsSection class]])
                [(SCArrayOfItemsSection *)cell.ownerSection dispatchEventRemoveRowAtIndexPath:indexPath];  // delete the cell
        }];
        deleteButton.backgroundColor = [UIColor redColor];
    
        return @[deleteButton, customButton];
    };
    
    // Swift
    self.tableViewModel.cellActions.editActions =
    {
        (cell, indexPath)->[AnyObject] in
    
        let customButton = UITableViewRowAction(style: .Default, title: "Button", handler:
        {
            (action, indexPath)->Void in
    
            NSLog("Custom edit action button tapped!")
    
            cell.ownerTableViewModel.tableView.editing = false  // collapse the cell back after completing custom edit action
        })
        customButton.backgroundColor = UIColor.greenColor() //arbitrary color
    
        let deleteButton = UITableViewRowAction(style: .Default, title: "Delete", handler:
        {
            (action, indexPath)->Void in
    
            if let itemsSection = cell.ownerSection as? SCArrayOfItemsSection
            {
                itemsSection.dispatchEventRemoveRowAtIndexPath(indexPath)  // delete the cell
            }
        })
    
        return [deleteButton, customButton]
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellEditActionsAction_Block editActions;

    Return Value

    An array of UITableViewRowAction objects representing the actions for the cell. Each action you provide is used to create a button that the user can tap.

  • Action gets called to provide custom swipe action buttons that appear when the user swipes the cell horizontally from it’s leading edge. For example, in a left-to-right language environment, they are displayed on the left side of the row when the user swipes from left to right.

    Use this action when you want to provide custom edit actions for your cell. When the user swipes horizontally, the table view moves the cell content aside to reveal your actions. Tapping one of the action buttons executes the handler block stored with the action object.

    Note

    It’s an NSArray that is returned here, not a UISwipeActionsConfiguration.

    Warning

    Only available in iOS 11 and later.

    Example:

        cellActions.leadingSwipeActions = ^NSArray*(SCTableViewCell *cell, NSIndexPath *indexPath) {
            UIContextualAction *inAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"In" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
                // code
                completionHandler(YES);
            }];
    
    
            UIContextualAction *outAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"Out" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
                // code
                completionHandler(YES);
            }];
    
            inAction.backgroundColor = [UIColor systemGreenColor];
            outAction.backgroundColor = [UIColor systemYellowColor];
    
            cell.leadingSwipePerformsFirstActionWithFullSwipe = NO;
    
            return @[inAction, outAction];
        };
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellLeadingSwipeActionsAction_Block leadingSwipeActions;

    Return Value

    An array of UIContextualAction objects representing the actions for the cell. Each action you provide is used to create a button that the user can tap on the leading edge of the cell.

  • Action gets called to provide custom swipe action buttons that appear when the user swipes the cell horizontally from it’s trailing edge. For example, in a left-to-right language environment, they are displayed on the right side of the row when the user swipes from right to left.

    Use this action when you want to provide custom edit actions for your cell. When the user swipes horizontally, the table view moves the cell content aside to reveal your actions. Tapping one of the action buttons executes the handler block stored with the action object.

    Return nil if you want the cell to display the default set of actions, although trailingSwipePerformsFirstActionWithFullSwipe will then always be the default of YES. You have to return your own Delete UIContextualAction, and set trailingSwipePerformsFirstActionWithFullSwipe to NO, if you want the Delete with no full swipe.

    Note

    It’s an NSArray that is returned here, not a UISwipeActionsConfiguration.

    Warning

    Only available in iOS 11 and later.

    Example:

     cellActions.trailingSwipeActions = ^NSArray*(SCTableViewCell *cell, NSIndexPath *indexPath) {
         UIContextualAction *archiveAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"Archive" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
             // code
             completionHandler(YES);
         }];
    
         UIContextualAction *deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Delete" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
             // code
             completionHandler(YES);
         }];
    
         archiveAction.backgroundColor = [UIColor systemOrangeColor];
         deleteAction.backgroundColor = [UIColor systemRedColor];
    
         cell.trailingSwipePerformsFirstActionWithFullSwipe = NO;
    
         return @[archiveAction, deleteAction];
     };
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellTrailingSwipeActionsAction_Block trailingSwipeActions;

    Return Value

    An array of UIContextualAction objects representing the actions for the cell. Each action you provide is used to create a button that the user can tap on the trailing edge of the cell.

  • Action gets called when the cell (or more typically one of the cell’s controls) becomes the first responder.

    Example:

    // Objective-C
    cellActions.didBecomeFirstResponder = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        NSLog(@"Cell at indexPath:%@ has become the first responder.", indexPath);
    };
    
    // Swift
    cellActions.didBecomeFirstResponder =
    {
        (cell, indexPath) in
    
        NSLog("Cell at indexPath:%@ has become the first responder.", indexPath)
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellAction_Block didBecomeFirstResponder;
  • Action gets called when the cell (or more typically one of the cell’s controls) resigns the first responder.

    Example:

    // Objective-C
    cellActions.didResignFirstResponder = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        NSLog(@"Cell at indexPath:%@ has resigned the first responder.", indexPath);
    };
    
    // Swift
    cellActions.didResignFirstResponder =
    {
        (cell, indexPath) in
    
        NSLog("Cell at indexPath:%@ has resigned the first responder.", indexPath)
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellAction_Block didResignFirstResponder;
  • Action gets called when the cell’s accessory button has been tapped.

    Example:

    // Objective-C
    cellActions.accessoryButtonTapped = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        NSLog(@"Cell at indexPath:%@ accessory button has been tapped.", indexPath);
    };
    
    // Swift
    cellActions.accessoryButtonTapped =
    {
        (cell, indexPath) in
    
        NSLog("Cell at indexPath:%@ accessory button has been tapped.", indexPath)
    }
    

    Note

    For this action to get called, you must first have the cell’s accessory button appear by setting its accessoryType property to UITableViewCellAccessoryDetailDisclosureButton.

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellAction_Block accessoryButtonTapped;
  • Action gets called when the cell keyboard’s return button has been tapped.

    This action is typically used to override STV’s behavior when the return button is tapped, and define a custom one.

    Example:

    // Objective-C
    cellActions.returnButtonTapped = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        [self doMyCustomAction];
        [cell.ownerTableViewModel moveToNextCellControl:YES];
    };
    
    // Swift
    cellActions.returnButtonTapped =
    {
        (cell, indexPath) in
    
        self.doMyCustomAction()
        cell.ownerTableViewModel.moveToNextCellControl(YES)
    }
    

    Note

    Action is only applicable to cells with controls that display a keyboard.

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellAction_Block returnButtonTapped;
  • Action gets called when the cell’s bound property value has changed via a cell control or a detail model.

    This action is typically used to provide a custom behavior when the cell’s value changes.

    Example:

    // Objective-C
    cellActions.valueChanged = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        NSLog(@"Cell at indexPath:%@ value has changed to: %@.", indexPath, cell.boundValue);
    };
    
    // Swift
    cellActions.valueChanged =
    {
        (cell, indexPath) in
    
        NSLog("Cell at indexPath:%@ value has changed to: %@.", indexPath, cell.boundValue)
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellAction_Block valueChanged;
  • Action gets called when the cell’s value needs to be validated.

    This action is typically used to provide a custom cell value validation.

    Example:

    // Objective-C
    cellActions.valueIsValid = ^BOOL(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        BOOL valid = NO;
    
        if([cell isKindOfClass:[SCTextFieldCell class]])
        {
            SCTextFieldCell *textFieldCell = (SCTextFieldCell *)cell;
    
            // Make sure the password field is at least 8 characters long
            if([textFieldCell.textField.text length] >= 8)
                valid = YES;
        }
    
        return valid;
    };
    
    // Swift
    cellActions.valueIsValid =
    {
        (cell, indexPath)->Bool in
    
        var valid = false
    
        if let textFieldCell = cell as? SCTextFieldCell
        {
            // Make sure the password field is at least 8 characters long
            if countElements(textFieldCell.textField.text) >= 8
            {
                valid = true
            }
        }
    
        return valid
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCBOOLReturnCellAction_Block valueIsValid;

    Return Value

    Return YES if the current cell value is valid, otherwise return NO.

  • Action is used to provide a value for calculated cells.

    Cells implementing this action are typically calculated cells that do not have their own values in the data store and depend on this action to provide a value. The return value is typically a mathematical operation on serveral other boundObject properties. For a more elaborate example on calculated cells, please refer to the CalculatedCellsApp bundled sample application.

    Example:

    // Objective-C
    cellActions.calculatedValue = ^NSObject*(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        NSNumber *speed = [cell.boundObject valueForKey:@"speed"];
        NSNumber *distance = [cell.boundObject valueForKey:@"distance"];
        CGFloat time = 0;
        if([speed floatValue])
            time = [distance floatValue]/[speed floatValue];
    
        return [NSNumber numberWithFloat:time];
    };
    
    // Swift
    cellActions.calculatedValue =
    {
        (cell, indexPath)->NSObject in
    
        let speed = cell.boundObject.valueForKey("speed") as! NSNumber
        let distance = cell.boundObject.valueForKey("distance") as! NSNumber
        var time = 0.0f
        if(speed.floatValue != 0)
            time = distance.floatValue()/speed.floatValue()
    
        return NSNumber.numberWithFloat(time)
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellCalculatedValueAction_Block calculatedValue;
  • Action gets called whenever a cell’s bound value has been loaded.

    This action is typically used to do any customization to the loaded bound value.

    Example:

    // Objective-C
    cellActions.didLoadBoundValue = ^NSObject*(SCTableViewCell *cell, NSIndexPath *indexPath, NSObject *value)
    {
        // Make sure all string spaces are trimmed before displaying string.
    
        NSString *stringValue = (NSStirng *)value;
        NSString *trimmedString = [stringValue stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    
        return trimmedString;
    };
    
    // Swift
    cellActions.didLoadBoundValue =
    {
        (cell, indexPath, value)->NSObject in
    
        // Make sure all string spaces are trimmed before displaying string.
        var trimmedString = ""
        if let stringValue = value as? String
        {
            trimmedString = stringValue.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
        }
    
        return trimmedString
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellBoundValueAction_Block didLoadBoundValue;
  • Action gets called before a cell’s bound value is committed to its bound object.

    This action is typically used to do any customization to the bound value before being committed.

    Example:

    // Objective-C
    cellActions.willCommitBoundValue = ^NSObject*(SCTableViewCell *cell, NSIndexPath *indexPath, NSObject *value)
    {
        // Make sure all string spaces are trimmed before committing the string.
    
        NSString *stringValue = (NSStirng *)value;
        NSString *trimmedString = [stringValue stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    
        return trimmedString;
    };
    
    // Swift
    cellActions.willCommitBoundValue =
    {
        (cell, indexPath, value)->NSObject in
    
        // Make sure all string spaces are trimmed before committing the string.
        var trimmedString = ""
        if let stringValue = value as? String
        {
            trimmedString = stringValue.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
        }
    
        return trimmedString
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellBoundValueAction_Block willCommitBoundValue;
  • Action gets called whenever a cell’s user defined custom button is tapped.

    This action is typically used to easily provide a custom behavior for the cell’s custom button(s).

    Example:

    // Objective-C
    cellActions.customButtonTapped = ^(SCTableViewCell *cell, NSIndexPath *indexPath, UIButton *button)
    {
        NSLog(@"Custom button with tag:%i has been tapped for cell at indexPath:%@.", button.tag, indexPath);
    };
    
    // Swift
    cellActions.customButtonTapped =
    {
        (cell, indexPath, button) in
    
        NSLog("Custom button with tag:%i has been tapped for cell at indexPath:%@.", button.tag, indexPath)
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellCustomButtonTappedAction_Block customButtonTapped;

Copying and Pasting

  • Action gets called to ask if the editing menu should be shown for the cell.

    Example:

    // Objective-C
    cellActions.shouldShowMenu = ^BOOL(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        return TRUE;
    };
    
    // Swift
    cellActions.shouldShowMenu =
    {
        (cell, indexPath)->Bool in
    
        return true
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCBOOLReturnCellAction_Block shouldShowMenu;

    Return Value

    Return TRUE to show editing menu, otherwise return FALSE.

  • Action gets called to ask if the editing menu should omit the Copy or Paste command for the cell.

    @action A selector type identifying the copy: or paste: method of the UIResponderStandardEditActions informal protocol. @sender The object that initially sent the copy: or paste: message.

    Example:

    // Objective-C
    cellActions.canPerformAction = ^BOOL(SCTableViewCell *cell, NSIndexPath *indexPath, SEL action, id sender)
    {
        return (action == @selector(copy:);  // only allow 'Copy'
    };
    
    // Swift
    cellActions.canPerformAction =
    {
        (cell, indexPath, action, sender)->Bool in
    
        return true   // allow all actions
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellCanPerformAction_Block canPerformAction;

    Return Value

    Return TRUE if the command corresponding to action should appear in the editing menu, otherwise return FALSE.

  • Action gets called to perform a copy or paste operation on the content of the cell.

    @action A selector type identifying the copy: or paste: method of the UIResponderStandardEditActions informal protocol. @sender The object that initially sent the copy: or paste: message.

    Example:

    // Objective-C
    cellActions.performAction = ^(SCTableViewCell *cell, NSIndexPath *indexPath, SEL action, id sender)
    {
        // perform operation here
    };
    
    // Swift
    cellActions.performAction =
    {
        (cell, indexPath, action, sender) in
    
        // perform operation here
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellPerformAction_Block performAction;

Detail Model Actions

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

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

    Example:

    // Objective-C
    cellActions.detailViewController = ^UIViewController*(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        MyCustomViewController *customVC = [[MyCustomViewController alloc] initWithNib:@"MyCustomViewController" bundle:nil];
    
        return customVC;
    };
    
    // Swift
    cellActions.detailViewController =
    {
        (cell, indexPath)->UIViewController in
    
        let customVC = MyCustomViewController(nibName: "MyCustomViewController", bundle: nil)
    
        return customVC
    }
    

    Note

    This action is only applicable to cells that generate detail views, such as SCSelectionCell and SCArrayOfObjectsCell.

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellDetailViewControllerAction_Block detailViewController;

    Return Value

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

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

    This action is typically used to provide your own custom detail model, instead of the one automatically generated by the cell. This might be needed in cases where the cell generates a detail SCArrayOfObjectsSection for example, and you need an SCArrayOfObjectsModel instead (to automatically generate sections for instance).

    Note

    It is much more common to use the detailViewController action instead, assigning the custom model in the custom view controller’s viewDidLoad method. This also gives you the chance to add a search bar (for example, to make use of SCArrayOfObjectsModel automatic searching functionality), or any other controls.

    Example:

    // Objective-C
    cellActions.detailTableViewModel = ^SCTableViewModel*(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        SCTableViewModel *detailModel = nil;
        if([cell isKindOfClass:[SCArrayOfObjectsCell class]])
        {
            detailModel = [SCArrayOfObjectsModel modelWithTableView:nil];
        }
    
        return detailModel;
    };
    
    // Swift
    cellActions.detailTableViewModel =
    {
        (cell, indexPath)->SCTableViewModel in
    
        if let arrayOfObjectsCell = cell as? SCArrayOfObjectsCell
        {
            return SCArrayOfObjectsModel(tableView: nil)
        }
        // else
        return nil
    }
    

    Note

    This action is only applicable to cells that generate detail views, such as SCSelectionCell and SCArrayOfObjectsCell.

    Declaration

    Objective-C

    @property (nonatomic, copy) SCCellDetailTableViewModelAction_Block detailTableViewModel;

    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.

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

    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:

    // Objective-C
    cellActions.detailModelCreated = ^(SCTableViewCell *cell, NSIndexPath *indexPath, SCTableViewModel *detailModel)
    {
        detailModel.tag = 100;
    };
    
    // Swift
    cellActions.detailModelCreated =
    {
        (cell, indexPath, detailModel) in
    
        detailModel.tag = 100
    }
    

    Note

    This action is only applicable to cells that generate detail views, such as SCSelectionCell.

    See

    detailModelConfigured

    Declaration

    Objective-C

    @property (nonatomic, copy) SCDetailModelCellAction_Block detailModelCreated;
  • Action gets called after the cell’s detail model is fully configured, including the addition of all automatically generated sections.

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

    Example:

    // Objective-C
    cellActions.detailModelConfigured = ^(SCTableViewCell *cell, NSIndexPath *indexPath, SCTableViewModel *detailModel)
    {
        SCTableViewSection *customSection = [SCTableViewSection section];
        SCCustomCell *customCell = [SCCustomCell cellWithText:@"Custom Cell"];
        [customSection addCell:customCell];
    
        [detailModel addSection:customSection];
    };
    
    // Swift
    cellActions.detailModelConfigured =
    {
        (cell, indexPath, detailModel) in
    
        let customSection = SCTableViewSection()
        let customCell = SCCustomCell(text: "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 cells that generate detail views, such as SCSelectionCell.

    Declaration

    Objective-C

    @property (nonatomic, copy) SCDetailModelCellAction_Block detailModelConfigured;
  • Action gets called when the cell’s detail model is about to be presented in its own view controller.

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

    Example:

    // Objective-C
    cellActions.detailModelWillPresent = ^(SCTableViewCell *cell, NSIndexPath *indexPath, SCTableViewModel *detailModel)
    {
        detailModel.viewController.title = @"My custom title";
    };
    
    // Swift
    cellActions.detailModelWillPresent =
    {
        (cell, indexPath, detailModel) in
    
        detailModel.viewController.title = "My custom title"
    }
    

    Note

    This action is only applicable to cells that generate detail views, such as SCSelectionCell.

    Declaration

    Objective-C

    @property (nonatomic, copy) SCDetailModelCellAction_Block detailModelWillPresent;
  • Action gets called when the cell’s detail model has been presented in its own view controller.

    Example:

    // Objective-C
    cellActions.detailModelDidPresent = ^(SCTableViewCell *cell, NSIndexPath *indexPath, SCTableViewModel *detailModel)
    {
        NSLog(@"Detail model has been presented.");
    };
    
    // Swift
    cellActions.detailModelDidPresent =
    {
        (cell, indexPath, detailModel) in
    
        NSLog("Detail model has been presented.")
    }
    

    Note

    This action is only applicable to cells that generate detail views, such as SCSelectionCell.

    Declaration

    Objective-C

    @property (nonatomic, copy) SCDetailModelCellAction_Block detailModelDidPresent;
  • Action gets called to give you a chance to decide if the detail model should be dismissed. Return YES to allow the detail model to be dismissed, otherwise return NO.

    Example:

    // Objective-C
    cellActions.detailModelShouldDismiss = ^BOOL(SCTableViewCell *cell, NSIndexPath *indexPath, SCTableViewModel *detailModel)
    {
        return YES;  // allow detail model to be dismissed
    };
    
    // Swift
    cellActions.detailModelShouldDismiss =
    {
        (cell, indexPath, detailModel)->Bool in
    
        return true  // allow detail model to be dismissed
    }
    

    Note

    This action is only applicable to cells that generate detail views, such as SCSelectionCell.

    Declaration

    Objective-C

    @property (nonatomic, copy) SCConditionalDetailModelCellAction_Block detailModelShouldDismiss;
  • Action gets called when the cell’s detail model’s view controller is about to be dismissed.

    Example:

    // Objective-C
    cellActions.detailModelWillDismiss = ^(SCTableViewCell *cell, NSIndexPath *indexPath, SCTableViewModel *detailModel)
    {
        NSLog(@"Detail model will be dismissed.");
    };
    
    // Swift
    cellActions.detailModelWillDismiss =
    {
        (cell, indexPath, detailModel) in
    
        NSLog("Detail model will be dismissed.")
    }
    

    Note

    This action is only applicable to cells that generate detail views, such as SCSelectionCell.

    Declaration

    Objective-C

    @property (nonatomic, copy) SCDetailModelCellAction_Block detailModelWillDismiss;
  • Action gets called when the cell’s detail model’s view controller has been dismissed.

    Example:

    // Objective-C
    cellActions.detailModelDidDismiss = ^(SCTableViewCell *cell, NSIndexPath *indexPath, SCTableViewModel *detailModel)
    {
        NSLog(@"Detail model has been dismissed.");
    };
    
    // Swift
    cellActions.detailModelDidDismiss =
    {
        (cell, indexPath, detailModel) in
    
        NSLog("Detail model has been dismissed.")
    }
    

    Note

    This action is only applicable to cells that generate detail views, such as SCSelectionCell.

    Declaration

    Objective-C

    @property (nonatomic, copy) SCDetailModelCellAction_Block detailModelDidDismiss;

Cell Text Field Related Actions

  • Implement action to control whether the specified text field’s text should change.

    Example:

    // Objective-C
    cellActions.shouldChangeCharactersInRange = ^BOOL(SCTableViewCell *cell, NSIndexPath *indexPath, UITextField *textField, NSRange range, NSString *replacementString)
    {
        NSLog(@"shouldChangeCharactersInRange called with replacement string: %@", replacementString);
    
        return YES;
    };
    
    // Swift
    cellActions.shouldChangeCharactersInRange = 
    {
        (cell, indexPath, textField, range, replacementString)->Bool in
    
        NSLog("shouldChangeCharactersInRange called with replacement string: %@", replacementString)
    
        return true
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCTextFieldShouldChangeCharactersInRangeAction_Block shouldChangeCharactersInRange;

SCImagePickerCell Specific Actions

  • Implement action to get notified when media is selected by SCImagePickerCell.

    Example:

    // Objective-C
    cellActions.didFinishPickingMedia = ^(SCImagePickerCell *imagePickerCell, NSIndexPath *indexPath, NSDictionary *mediaInfo, ALAsset *mediaAsset)
    {
        // Determine selected media date
        NSDate *date = [mediaAsset valueForProperty:ALAssetPropertyDate];
        NSLog(@"Selected media date: %@", date);
    };
    
    // Swift
    cellActions.didFinishPickingMedia =
    {
        (imagePickerCell, indexPath, mediaInfo, mediaAsset) in
    
        // Determine selected media date
        let date = mediaAsset.valueForProperty(ALAssetPropertyDate)
        NSLog("Selected media date: %@", date)
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCImagePickerDidFinishPickingMediaAction_Block didFinishPickingMedia;
  • Implement action to provide your own custom image name of the SCImagePickerCell image.

    Example:

    // Objective-C
    cellActions.imageName = ^NSString*(SCImagePickerCell *imagePickerCell, NSIndexPath *indexPath)
    {
        return @"My Custom Image Name";
    };
    
    // Swift
    cellActions.imageName =
    {
        (imagePickerCell, indexPath)->String in
    
        return "My Custom Image Name"
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCImagePickerImageNameAction_Block imageName;
  • Implement action to provide your own custom code for saving the SCImagePickerCell image to imagePath.

    Example:

    // Objective-C
    cellActions.saveImage = ^(SCImagePickerCell *imagePickerCell, NSIndexPath *indexPath, NSString *imagePath)
    {
        [UIImageJPEGRepresentation(imagePickerCell.selectedImage, 80) writeToFile:imagePath atomically:YES];
    };
    
    // Swift
    cellActions.saveImage =
    {
        (imagePickerCell, indexPath, imagePath) in
    
        UIImageJPEGRepresentation(imagePickerCell.selectedImage, 80).writeToFile(imagePath, atomically: true)
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCImagePickerSaveImageAction_Block saveImage;
  • Implement action to provide your own custom code for loading the SCImagePickerCell image from imagePath.

    Example:

    // Objective-C
    cellActions.loadImage = ^UIImage*(SCImagePickerCell *imagePickerCell, NSIndexPath *indexPath, NSString *imagePath)
    {
        return [UIImage imageWithContentsOfFile:imagePath];
    };
    
    // Swift
    cellActions.loadImage =
    {
        (imagePickerCell, indexPath, imagePath)->UIImage in
    
        return UIImage(contentsOfFile: imagePath)
    }
    

    Declaration

    Objective-C

    @property (nonatomic, copy) SCImagePickerLoadImageAction_Block loadImage;

Miscellaneous

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

    Declaration

    Objective-C

    - (void)setActionsTo:(SCCellActions *)actions overrideExisting:(BOOL)override;

    Parameters

    actions

    The source ‘SCCellActions’ class.

    override

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