FUIDatePickerFormCell

public class FUIDatePickerFormCell: FUIInlineValidationTableViewCell, FUIPropertyFormCell

A UITableViewCell subclass, which allows a user to read or enter a value, using a date picker.

FUIDatePickerFormCell

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 Date

And an onChangeHandler:

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

Optionally, UITableViewController could provide

  • dateFormatter: A developer-defined UIDateFormatter, for transposing between Date type and String.
  • datePickerMode: The UIDatePickerMode for the date picker. Default is .dateAndTime. Note that .countDownTimer mode is not supported. Use the FUIDurationPickerFormCell for duration values.
  • isEditable: Indicates if the cell’s value may be modified. Defaults to true.

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

Important

The app’s UITableViewController must subclass FUIFormTableViewController
let dateFormatter = DateFormatter()

override func viewDidLoad() {
    super.viewDidLoad()

    dateFormatter.dateFormat = "dd-MM-yyyy"
    self.tableView.register(FUIDatePickerFormCell.self, forCellReuseIdentifier: FUIDatePickerFormCell.reuseIdentifier)
    // ...
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCell(withIdentifier: FUIDatePickerFormCell.reuseIdentifier, for: indexPath) as! FUIDatePickerFormCell
    cell.keyName = "End Date"

    cell.dateFormatter = dateFormatter
    cell.datePickerMode = .date
    cell.value = cell.dateFormatter.date(from: myObject.endDate)   // "02-17-2017"

     // MARK:  implement onChangeHandler
     cell.onChangeHandler = { newValue in
        myObject.endDate = cell.dateFormatter.string(from: newValue)
     }

     return cell
}

  • The value type is Date.

    Declaration

    Swift

    public typealias ValueType = Date
  • The value of the property.

    Declaration

    Swift

    public var value: Date
  • Implementation of change handler. Is invoked on changes to the value property.

    Declaration

    Swift

    public var onChangeHandler: ((Date) -> Void)?
  • The default cell reuse identifier.

    Declaration

    Swift

    open static var reuseIdentifier: String
  • Indicates if the value of the cell could be changed or not. The default is true.

    Declaration

    Swift

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

    Declaration

    Swift

    public var keyName: String?
  • The placeholder text for the value text field.

    Declaration

    Swift

    public var placeholderText: String?
  • The DateFormatter to be used to display the selected Date. Default formatter:

    • for UIDatePickerMode.dateAndTime it is medium date style followed by short time style.
    • for UIDatePickerMode.date it is medium date style
    • for UIDatePickerMode.time it is short time style

    Declaration

    Swift

    public var dateFormatter: DateFormatter?
  • The UIDatePickerMode for the UIDatePicker for this cell. The default value is UIDatePickerMode.dateAndTime.

    Important

    important : UIDatePickerMode.countDownTimer is not allowed here. Use FUIDurationPickerFormCell for count down mode.

    Declaration

    Swift

    public var datePickerMode: UIDatePickerMode
  • The UIDatePicker for this cell. It will be displayed only when this cell is selected.

    Declaration

    Swift

    @IBOutlet public weak var datePicker: UIDatePicker!