FUISwitchFormCell

open class FUISwitchFormCell: FUIInlineValidationTableViewCell, FUIPropertyFormCell

The reusable UI component implemented as an UITableViewCell to allow user to choose a boolean value using a switch for a property.

FUISwitchFormCell

The developer should set the following properties on the cell, in their implementation of UITableViewDataSource cellForRow(at:) function:

  • keyName: The key name of the property
  • value: The value of the property, as Bool
  • isEditable: Indicates if the cell’s value may be modified. Defaults to true.

And, an onChangeHandler:

  • onChangeHandler: a handler closure, which is invoked on changes to the value

The following is an example of usage in an application UITableViewController:

Important

The app’s UITableViewController must subclass FUIFormTableViewController
override func viewDidLoad() {
   super.viewDidLoad()
   self.tableView.register(FUISwitchFormCell.self, forCellReuseIdentifier: FUISwitchFormCell.reuseIdentifier)
   // ...
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
   // ...
   let cell = tableView.dequeueReusableCell(withIdentifier: FUISwitchFormCell.reuseIdentifier, for: indexPath) as! FUISwitchFormCell
   cell.keyName = "Confirmed"
   cell.value = myObject.isConfirmed

   // MARK:  implement onChangeHandler
   cell.onChangeHandler = { newValue in
       myObject.isConfirmed = newValue
   }

   return cell
}

  • The value type is Bool.

    Declaration

    Swift

    public typealias ValueType = Bool
  • The default cell reuse identifier.

    Declaration

    Swift

    open static var reuseIdentifier: String
  • The value of the property. Default to be false.

    Declaration

    Swift

    open var value: Bool = false
  • Implementation of change handler. Is invoked on changes to the value property.

    Declaration

    Swift

    open var onChangeHandler: ((Bool) -> Void)?
  • Indicates if the value of the cell could be changed or not. The default is true.

    Declaration

    Swift

    open var isEditable = true
  • The key name of the property.

    Declaration

    Swift

    open var keyName: String?
  • The UILable displaying the key name field.

    Declaration

    Swift

    @IBOutlet public weak var keyLabel: UILabel!
  • The UISwitch displaying the boolean value.

    Declaration

    Swift

    @IBOutlet public var switchView: UISwitch!