SCCellActions Class Reference
Inherits from | NSObject |
Declared in | SCCellActions.h |
Overview
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.
Tasks
Actions
-
willStyle
property -
willConfigure
property -
didLayoutSubviews
property -
willDisplay
property -
lazyLoad
property -
willSelect
property -
didSelect
property -
willDeselect
property -
didDeselect
property -
customEditingStyle
property -
editActions
property -
didBecomeFirstResponder
property -
didResignFirstResponder
property -
accessoryButtonTapped
property -
returnButtonTapped
property -
valueChanged
property -
valueIsValid
property -
calculatedValue
property -
didLoadBoundValue
property -
willCommitBoundValue
property -
customButtonTapped
property
Copying and Pasting
-
shouldShowMenu
property -
canPerformAction
property -
performAction
property
Detail Model Actions
-
detailViewController
property -
detailTableViewModel
property -
detailModelCreated
property -
detailModelConfigured
property -
detailModelWillPresent
property -
detailModelDidPresent
property -
detailModelShouldDismiss
property -
detailModelWillDismiss
property -
detailModelDidDismiss
property -
shouldChangeCharactersInRange
property -
didFinishPickingMedia
property -
imageName
property -
saveImage
property -
loadImage
property
Miscellaneous
Properties
accessoryButtonTapped
Action gets called when the cell’s accessory button has been tapped.
@property (nonatomic, copy) SCCellAction_Block accessoryButtonTapped
Discussion
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.
Declared In
SCCellActions.h
calculatedValue
Action is used to provide a value for calculated cells.
@property (nonatomic, copy) SCCellCalculatedValueAction_Block calculatedValue
Discussion
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)
}
Declared In
SCCellActions.h
canPerformAction
Action gets called to ask if the editing menu should omit the Copy or Paste command for the cell.
@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.
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
}
Discussion
@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.
Declared In
SCCellActions.h
customButtonTapped
Action gets called whenever a cell’s user defined custom button is tapped.
@property (nonatomic, copy) SCCellCustomButtonTappedAction_Block customButtonTapped
Discussion
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)
}
Declared In
SCCellActions.h
customEditingStyle
Action gives you the opportunity to provide your own custom cell editing style.
@property (nonatomic, copy) SCCellCustomEditingStyleAction_Block customEditingStyle
Return Value
Return a valid UITableViewCellEditingStyle value.
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;
}
Declared In
SCCellActions.h
detailModelConfigured
Action gets called after the cell’s detail model is fully configured, including the addition of all automatically generated sections.
@property (nonatomic, copy) SCDetailModelCellAction_Block detailModelConfigured
Discussion
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.
Declared In
SCCellActions.h
detailModelCreated
Action gets called right after the cell’s detail model is created, before configuration is set or any sections are added.
@property (nonatomic, copy) SCDetailModelCellAction_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:
// 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 Also
Declared In
SCCellActions.h
detailModelDidDismiss
Action gets called when the cell’s detail model’s view controller has been dismissed.
@property (nonatomic, copy) SCDetailModelCellAction_Block detailModelDidDismiss
Discussion
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.
Declared In
SCCellActions.h
detailModelDidPresent
Action gets called when the cell’s detail model has been presented in its own view controller.
@property (nonatomic, copy) SCDetailModelCellAction_Block detailModelDidPresent
Discussion
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.
Declared In
SCCellActions.h
detailModelShouldDismiss
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.
@property (nonatomic, copy) SCConditionalDetailModelCellAction_Block detailModelShouldDismiss
Discussion
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.
Declared In
SCCellActions.h
detailModelWillDismiss
Action gets called when the cell’s detail model’s view controller is about to be dismissed.
@property (nonatomic, copy) SCDetailModelCellAction_Block detailModelWillDismiss
Discussion
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.
Declared In
SCCellActions.h
detailModelWillPresent
Action gets called when the cell’s detail model is about to be presented in its own view controller.
@property (nonatomic, copy) SCDetailModelCellAction_Block detailModelWillPresent
Discussion
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.
Declared In
SCCellActions.h
detailTableViewModel
Action gets called to give you the chance to return a custom detail model for the cell’s detail view controller.
@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.
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
}
Discussion
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.
Note: This action is only applicable to cells that generate detail views, such as SCSelectionCell and SCArrayOfObjectsCell.
Declared In
SCCellActions.h
detailViewController
Action gets called to give you the chance to return a custom detail view controller for the cell.
@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.
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
}
Discussion
This action is typically used to provide your own custom detail view controller, instead of the one automatically generated by the cell.
Note: This action is only applicable to cells that generate detail views, such as SCSelectionCell and SCArrayOfObjectsCell.
Declared In
SCCellActions.h
didBecomeFirstResponder
Action gets called when the cell (or more typically one of the cell’s controls) becomes the first responder.
@property (nonatomic, copy) SCCellAction_Block didBecomeFirstResponder
Discussion
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)
}
Declared In
SCCellActions.h
didDeselect
Action gets called when the cell has been deselected.
@property (nonatomic, copy) SCCellAction_Block didDeselect
Discussion
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)
}
Declared In
SCCellActions.h
didFinishPickingMedia
Implement action to get notified when media is selected by SCImagePickerCell.
@property (nonatomic, copy) SCImagePickerDidFinishPickingMediaAction_Block didFinishPickingMedia
Discussion
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)
}
Declared In
SCCellActions.h
didLayoutSubviews
Action gets called after the cell has laid out all its subviews.
@property (nonatomic, copy) SCCellAction_Block didLayoutSubviews
Discussion
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)
}
Declared In
SCCellActions.h
didLoadBoundValue
Action gets called whenever a cell’s bound value has been loaded.
@property (nonatomic, copy) SCCellBoundValueAction_Block didLoadBoundValue
Discussion
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
}
Declared In
SCCellActions.h
didResignFirstResponder
Action gets called when the cell (or more typically one of the cell’s controls) resigns the first responder.
@property (nonatomic, copy) SCCellAction_Block didResignFirstResponder
Discussion
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)
}
Declared In
SCCellActions.h
didSelect
Action gets called when the cell has been selected.
@property (nonatomic, copy) SCCellAction_Block didSelect
Discussion
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)
}
Declared In
SCCellActions.h
editActions
Action gets called to provide custom edit action buttons that appear when the user swipes the cell horizontally.
@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.
Discussion
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]
}
Declared In
SCCellActions.h
imageName
Implement action to provide your own custom image name of the SCImagePickerCell image.
@property (nonatomic, copy) SCImagePickerImageNameAction_Block imageName
Discussion
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"
}
Declared In
SCCellActions.h
lazyLoad
Action gets called after the cell has been displayed and the table view has stopped scrolling.
@property (nonatomic, copy) SCCellAction_Block lazyLoad
Discussion
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)
}
Declared In
SCCellActions.h
loadImage
Implement action to provide your own custom code for loading the SCImagePickerCell image from imagePath.
@property (nonatomic, copy) SCImagePickerLoadImageAction_Block loadImage
Discussion
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)
}
Declared In
SCCellActions.h
performAction
Action gets called to perform a copy or paste operation on the content of the cell.
@property (nonatomic, copy) SCCellPerformAction_Block performAction
Discussion
@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
}
Declared In
SCCellActions.h
returnButtonTapped
Action gets called when the cell keyboard’s return button has been tapped.
@property (nonatomic, copy) SCCellAction_Block returnButtonTapped
Discussion
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.
Declared In
SCCellActions.h
saveImage
Implement action to provide your own custom code for saving the SCImagePickerCell image to imagePath.
@property (nonatomic, copy) SCImagePickerSaveImageAction_Block saveImage
Discussion
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)
}
Declared In
SCCellActions.h
shouldChangeCharactersInRange
Implement action to control whether the specified text field’s text should change.
@property (nonatomic, copy) SCTextFieldShouldChangeCharactersInRangeAction_Block shouldChangeCharactersInRange
Discussion
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
}
Declared In
SCCellActions.h
shouldShowMenu
Action gets called to ask if the editing menu should be shown for the cell.
@property (nonatomic, copy) SCBOOLReturnCellAction_Block shouldShowMenu
Return Value
Return TRUE to show editing menu, otherwise return FALSE.
Example:
// Objective-C
cellActions.shouldShowMenu = ^BOOL(SCTableViewCell *cell, NSIndexPath *indexPath)
{
return TRUE;
};
// Swift
cellActions.shouldShowMenu =
{
(cell, indexPath)->Bool in
return true
}
Declared In
SCCellActions.h
valueChanged
Action gets called when the cell’s bound property value has changed via a cell control or a detail model.
@property (nonatomic, copy) SCCellAction_Block valueChanged
Discussion
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)
}
Declared In
SCCellActions.h
valueIsValid
Action gets called when the cell’s value needs to be validated.
@property (nonatomic, copy) SCBOOLReturnCellAction_Block valueIsValid
Return Value
Return YES if the current cell value is valid, otherwise return NO.
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
}
Discussion
This action is typically used to provide a custom cell value validation.
Declared In
SCCellActions.h
willCommitBoundValue
Action gets called before a cell’s bound value is committed to its bound object.
@property (nonatomic, copy) SCCellBoundValueAction_Block willCommitBoundValue
Discussion
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
}
Declared In
SCCellActions.h
willConfigure
Action gets called before the cell is configured.
@property (nonatomic, copy) SCCellAction_Block willConfigure
Discussion
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
}
Declared In
SCCellActions.h
willDeselect
Action gets called when the cell is about to be deselected.
@property (nonatomic, copy) SCBOOLReturnCellAction_Block willDeselect
Return Value
Return FALSE to prevent deselection, otherwise return TRUE.
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
}
Declared In
SCCellActions.h
willDisplay
Action gets called before the cell is displayed.
@property (nonatomic, copy) SCCellAction_Block willDisplay
Discussion
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.
Declared In
SCCellActions.h
willSelect
Action gets called when the cell is about to be selected.
@property (nonatomic, copy) SCBOOLReturnCellAction_Block willSelect
Return Value
Return FALSE to prevent selection, otherwise return TRUE.
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
}
Declared In
SCCellActions.h
willStyle
Action gets called before the cell gets automatically styled using the provided theme.
@property (nonatomic, copy) SCCellAction_Block willStyle
Discussion
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 Also
Declared In
SCCellActions.h
Instance Methods
setActionsTo:overrideExisting:
Method assigns all the actions of another ‘SCCellActions’ class to the current one.
- (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.
Declared In
SCCellActions.h