FUIFilterFormCell

open 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.

Color setting:

Setting text color of filter buttons for a state using setTintColor(_:for:) api. Currently disabled, normal and selected are supported.

 cell.setTintColor(UIColor.red, for: .normal)

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 = { [weak self] newValue in
        self.applyFilter(forDimensions: newValue)      // here, the cell input is set to a filter function
     }

    return cell
 }

## Theming Supported style classes

 fdlFUIFilterFormCell
 fdlFUIFilterFormCell_keyLabel
 fdlFUIFilterFormCell_item_contentView
 fdlFUIFilterFormCell_item_titleLabel
 fdlFUIFilterFormCell_item_contentView_selected
 fdlFUIFilterFormCell_item_titleLabel_selected
  • Reuse identifier

    Declaration

    Swift

    open class var reuseIdentifier: String { get }
  • The type of the value

    Declaration

    Swift

    public typealias ValueType = [Int]
  • Indicate whether the user can select an item or not. It is set to true by default.

    Declaration

    Swift

    public var isEditable: Bool { get set }
  • isEnabled and isEditable are in sync.

    Declaration

    Swift

    override public var isEnabled: Bool { get set }
  • The value of the cell.

    Declaration

    Swift

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

    Declaration

    Swift

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

    Note

    Setting this property will be ignored when property filterGroup is not nil.

    Declaration

    Swift

    @objc
    public var valueOptions: [String] { get set }
  • Using the a FUIFilterGroup to initialize the allowsMultipleSelection, allowsEmptySelection, valueOptions, and value properties. The valueOptions will be the title properties of the FUIFilterItem objects in the group. And the value property will be set based on the isActive property of items.

    Note

    The isActive property of the items will be updated according to the user actions. There is no need to update them in the onChangeHandler.

    Declaration

    Swift

    public var filterGroup: FUIFilterGroup? { get set }
  • The key name of the cell.

    Declaration

    Swift

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

    Note

    Setting this property will be ignored when property filterGroup is not nil.

    Declaration

    Swift

    public var allowsMultipleSelection: Bool { get set }
  • Indicates if empty selection is allowed. Defaults to true.

    Note

    Setting this property will be ignored when property filterGroup is not nil.

    Declaration

    Swift

    public var allowsEmptySelection: Bool { get set }
  • The UILabel holds the key name string.

    Declaration

    Swift

    @IBInspectable
    @IBOutlet
    public private(set) weak var keyLabel: UILabel! { get }
  • The collection view containing items to be displayed.

    Declaration

    Swift

    @IBOutlet
    public private(set) weak var collectionView: UICollectionView! { get }