FUIListPickerFormCell
public class FUIListPickerFormCell: FUIInlineValidationTableViewCell, FUIPickerFormCell
The reusable UI component implemented as an UITableViewCell
to display a key-value pair property, which is integrated with a FUIListPicker
controller for displaying a list of values.
### Single-line version
### Multi-line version
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 default selections.valueOptions
: The list of optional values user may choose from.allowsMultipleSelection
: Indicates if user can select multiple values. Default is true, meaning by default user may select multiple values.isEditable
: If the selection(s) could be modified or not. The default is true.listPicker
: TheFUIListPicker
for thisFUIListPickerFormCell
.
Note that the display of the selections in the valueTextField
is the
responsibility of the developer if the dataSource
property of the listPicker
is set. Developer is to set the text of the valueTextField
to reflect the selections.
Otherwise, if developer sets valueOptions
and leaves dataSource
of listPicker
to nil,
then the text in valueTextField
will be set internally.
Here are the code snippets in app’s UITableViewController
implementation:
(The app’s UITableViewController
needs to be a subclass of FUIFormTableViewController
.)
var propValue7: [Int] = [1, 3, 6]
var valueOptions7 = ["One", "Two", "Three", "Four", "Five", "Six", "Seven"]
var listPickerDataSource7 = StringListPickerDataSource(options: valueOptions7)
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.register(FUIListPickerFormCell.self, forCellReuseIdentifier: FUIListPickerFormCell.reuseIdentifier)
// ...
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// ...
let cell = tableView.dequeueReusableCell(withIdentifier: FUIListPickerFormCell.reuseIdentifier, for: indexPath) as! FUIListPickerFormCell
cell.keyName = "Choose Multiple"
cell.value = propValue7
cell.allowsMultipleSelection = true
cell.valueTextField.text = descriptionForSelectedStrings(valueOptions7, at: propValue7) // See below
cell.listPicker.dataSource = listPickerDataSource7
cell.listPicker.searchResultsUpdating = listPickerDataSource7
cell.listPicker.isSearchEnabled = true
cell.listPicker.prompt = "Please select multiple items"
cell.listPicker.searchBar?.isBarcodeScannerEnabled = true
cell.listPicker.searchBar?.barcodeScanner?.scanMode = .EAN_UPC
cell.listPicker.searchBar?.barcodeScanner?.scanResultTransformer = { (scanString) -> String in
return self.transformStringToSearchBar(scanResultString: scanString)
}
// MARK: implement onChangeHandler
cell.onChangeHandler = { [unowned self] newValue in
self.propValue3 = newValue
}
return cell
// ...
}
func descriptionForSelectedStrings(_ options: [String], at indexes: [Int]) -> String {
return options.enumerated().filter({ (index, element) -> Bool in
return indexes.contains(index)
}).reduce ("") { string, element in
return string.isEmpty ? element.1 : "\(string), \(element.1)"
}
}
-
The value type is String array.
Declaration
Swift
public typealias ValueType = [Int]
-
The default cell reuse identifier.
Declaration
Swift
open static var reuseIdentifier: String
-
The value is the selected strings.
Declaration
Swift
public var value: [Int] = [Int]()
-
Implementation of change handler. Is invoked on changes to the
value
property.Declaration
Swift
public var onChangeHandler: ((Array<Int>) -> Void)?
-
Indicates if this cell is editable or not, i.e., the selections 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 array of the valid options.
Declaration
Swift
public var valueOptions: [String] = [String]()
-
The
FUIListPicker
for thisFUIListPickerFormCell
.Declaration
Swift
public var listPicker: FUIListPicker!
-
Indicates if user can select multiple values. Default is true, meaning by default user may select multiple values.
Declaration
Swift
public var allowsMultipleSelection: Bool = true
-
Indicates if empty selection is allowed. Default is true, meaning by default user must select at least one item.
Declaration
Swift
public var allowsEmptySelection = true
-
The UILabel holds the key name string.
Declaration
Swift
@IBOutlet public weak var keyLabel: UILabel!
-
The UITextField holds the selected value strings.
Declaration
Swift
@IBOutlet public weak var valueTextField: UITextField!
-
If this property is true, the cancel button will be shown on the right side of the navigation bar to let user undo the change when tapped. The default is false. i.e., the cancel button will not be shown.
Declaration
Swift
public var isUndoEnabled = false