FUIFilterFormCell

public class FUIFilterFormCell: FUIInlineValidationTableViewCell, FUIPickerFormCell, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout

A UITableViewCell subclass, which allows a user to read or enter a set of values, using a grid of buttons. Commonly used for composing filters.

FUIFilterFormCell

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: An array of the selected indexes in the control. Uses the same index as the valueOptions array.
  • `valueOptions: A String array, of titles for the buttons in the control

And an onChangeHandler:

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

Optionally, the developer may provide

  • allowsMultipleSelection: Indicates if multiple buttons may be selected simultaneously (true). If false, the control behaves in radio mode. Defaults to true.
  • allowsEmptySelection: Indicates if the control allows zero items to be selected (true). If false, then once a value has been selected by the developer or user, taps by the user on the last selected item will be ignored, instead of de-selecting the item. Defaults to true.
  • 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
 // optionally, create an array of value option to localized string mappings
  let buttonTitles: [[String: String]] = [["radius": "Distance"], ["price": "Price"], ["rating": "Ratings"], ["avail": "Availability"]]

 // Register FUIFilterFormCell in viewDidLoad() method in the controller.
 override func viewDidLoad() {
     super.viewDidLoad()
     self.tableView.register(FUIFilterFormCell.self, forCellReuseIdentifier: FUIFilterFormCell.reuseIdentifier)
 }

 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
     let cell = tableView.dequeueReusableCell(withIdentifier: FUIFilterFormCell.reuseIdentifier, for: indexPath) as! FUIFilterFormCell

     cell.valueOptions = buttonTitles.flatMap { $0.map { $0.value }}
     cell.keyName = "Sort By"
     cell.value = [1]
     cell.allowsMultipleSelection = true
     cell.allowsEmptySelection = false

     // MARK:  implement onChangeHandler
     cell.onChangeHandler = { newValue in
        self.applyFilter(forDimensions: newValue)      // here, the cell input is set to a filter function
     }

    return cell
 }

  • The type of the value

    Declaration

    Swift

    public typealias ValueType = [Int]
  • Reuse identifier

    Declaration

    Swift

    open static var reuseIdentifier: String
  • Indicate whether the user can select an item or not. It is set to true by default.

    Declaration

    Swift

    public var isEditable: Bool = true
  • The value of the cell.

    Declaration

    Swift

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

    Declaration

    Swift

    public var onChangeHandler: ((Array<Int>) -> Void)?
  • The array of the valid options.

    Declaration

    Swift

    public var valueOptions: [String]
  • The key name of the cell.

    Declaration

    Swift

    public var keyName: String?
  • Indicates if user may select multiple values. Defaults to true

    Declaration

    Swift

    public var allowsMultipleSelection = true
  • Indicates if empty selection is allowed.

    Declaration

    Swift

    public var allowsEmptySelection = true
  • The UILabel holds the key name string.

    Declaration

    Swift

    @IBOutlet public weak var keyLabel: UILabel!
  • The collection view containing items to be displayed.

    Declaration

    Swift

    @IBOutlet public weak var collectionView: UICollectionView!