FUIDatePickerFormCell
public class FUIDatePickerFormCell: FUIInlineValidationTableViewCell, FUIPropertyFormCell
A UITableViewCell
subclass, which allows a user to read or enter a value, using a date picker.
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, asDate
And an onChangeHandler
:
onChangeHandler
: a handler closure, which is invoked on changes to the value
Optionally, UITableViewController could provide
dateFormatter
: A developer-definedUIDateFormatter
, for transposing betweenDate
type andString
.datePickerMode
: TheUIDatePickerMode
for the date picker. Default is.dateAndTime
. Note that.countDownTimer
mode is not supported. Use theFUIDurationPickerFormCell
for duration values.isEditable
: Indicates if the cell’s value may be modified. Defaults totrue
.
The following is an example of usage in an application UITableViewController
:
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 selectedDate
. 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?
- for
-
The
UIDatePickerMode
for theUIDatePicker
for this cell. The default value isUIDatePickerMode.dateAndTime
.Important
important :UIDatePickerMode.countDownTimer
is not allowed here. UseFUIDurationPickerFormCell
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!