EnterpriseDS Documentation

Class DSSelect​Table​View​Cell

@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()
    }
}
DSSelectTableViewCell DSSelectTableViewCell UITableViewCell UITableViewCell DSSelectTableViewCell->UITableViewCell DSSelectControl DSSelectControl DSSelectTableViewCell->DSSelectControl

Conforms To

DSSelectControl

A protocol extension for select controls.

UITableViewCell

Properties

select​Delegate

@IBOutlet public weak var selectDelegate: DSSelectTableViewCellDelegate? 

The delegate which receives updates on the DSSelectTableViewCell's state.

is​Enabled

@IBInspectable public var isEnabled: Bool = true  

Returns true if the component is enabled and allows changing the value.

label​Text

@IBInspectable public var labelText: String?  

The text to be displayed in the label.

helper​Text

@IBInspectable public var helperText: String?  

The text to be displayed as helper (below the label) to clarify what the field's value represents.

value

public var value: DSSelectOption?  

The value of the field.

options

public var options: [DSSelectOption] = []  

The ordered list of valid values that can be selected for this field.

validation​Rules

public var validationRules  

The array of ValidationRule objects to be used for validating the current state of the field.

validation​State

public private(set) var validationState: DSValueValidationState = .unvalidated

Methods

awake​From​Nib()

public override func awakeFromNib()  

prepare​For​Interface​Builder()

public override func prepareForInterfaceBuilder()  

layout​Subviews()

public override func layoutSubviews()  

add(validation​Rule:​)

func add(validationRule rule: DSValidationRule)  

Adds a validation rule to be used for validating the current value.

Parameters

validation​Rule DSValidation​Rule

A ValidationRule object to be used for checking a validation

add(validation​Rules:​)

func add(validationRules rules: [DSValidationRule])  

Adds an array of validation rules to be used for validating the current value.

Parameters

validation​Rules [DSValidation​Rule]

A ValidationRule array to be used for checking validations

remove​All​Validation​Rules()

func removeAllValidationRules()  

Removes all validation rules.

validate()

@discardableResult func validate() -> DSValidationRule?  

Returns the validation status of the current value based on the current validation rules.