Class
DSSelectTableViewCell
@IBDesignable public final class DSSelectTableViewCell: UITableViewCell, DSSelectControl
An Enterprise-styled option selection cell. This should be used when a user needs to select a value from a set of options. Only for use as a cell in UITableView.
For storyboards, add a UITableViewCell to your list of static cells and change the class name to DSSelectTableViewCell. Works with dynamic tables as normal.
Connect the cell at creation (or later):
guard let cell = tableView.cellForRow(at: indexPath) as? DSSelectTableViewCell else { return }
let options = [
DSSelectOption(data: "apple", label: "Apple"),
DSSelectOption(data: "banana", label: "Banana"),
DSSelectOption(data: "carrot", label: "Carrot")
]
cell.selectDelegate = self
cell.options = options
cell.value = options[0]
When the cell is tapped, navigate to the options list:
cell.showOptionSelection(on: navigationController)
Handle value changes to this cell in your DSSelectTableViewCellDelegate:
func selectValueDidChange(_ select: DSSelectTableViewCell, value: DSSelectOption?) {
guard let indexPath = tableView.indexPath(for: select) else { return }
values[indexPath.row] = value
// we do this in case the height of the cell changes
UIView.performWithoutAnimation {
tableView.beginUpdates()
tableView.endUpdates()
}
}
Relationships
Conforms To
DSSelectControl
A protocol extension for select controls.
UITableViewCell
Properties
selectDelegate
@IBOutlet public weak var selectDelegate: DSSelectTableViewCellDelegate?
The delegate which receives updates on the DSSelectTableViewCell's state.
isEnabled
@IBInspectable public var isEnabled: Bool = true
Returns true if the component is enabled and allows changing the value.
helperText
@IBInspectable public var helperText: String?
The text to be displayed as helper (below the label) to clarify what the field's value represents.
options
public var options: [DSSelectOption] = []
The ordered list of valid values that can be selected for this field.
validationRules
public var validationRules
The array of ValidationRule objects to be used for validating the current state of the field.
validationState
public private(set) var validationState: DSValueValidationState = .unvalidated
Methods
awakeFromNib()
public override func awakeFromNib()
prepareForInterfaceBuilder()
public override func prepareForInterfaceBuilder()
layoutSubviews()
public override func layoutSubviews()
add(validationRule:)
func add(validationRule rule: DSValidationRule)
Adds a validation rule to be used for validating the current value.
Parameters
Name | Type | Description |
---|---|---|
validationRule | DSValidationRule |
A ValidationRule object to be used for checking a validation |
add(validationRules:)
func add(validationRules rules: [DSValidationRule])
Adds an array of validation rules to be used for validating the current value.
Parameters
Name | Type | Description |
---|---|---|
validationRules | [DSValidationRule] |
A ValidationRule array to be used for checking validations |
validate()
@discardableResult func validate() -> DSValidationRule?
Returns the validation status of the current value based on the current validation rules.