FUISortFilterViewController
@MainActor
public class FUISortFilterViewController : FUIFormTableViewController
FUISortFilterViewController allows users to narrow down results from a long list by setting criteria. Users are able to reset filters and return to the initial list.
Various ControlTypes, such as switch, filter, rating, etc. are supported for sort and filter criteria.
Initialization and Configuration Example:
let vc = FUISortFilterViewController()
// This is required. This is a 2D array of sort and filter criteria. The first dimension of the array is `UITableView` sections and the second dimension is `ControlTypes(cells`) for that section.
vc.values = [
[
.filter([0], ["Distance", "Availability", "Ratings", "Price"], "Sort by", false, true)
],
[
.switch(true, "Show Favorites"),
.listPicker([0], ["None", "John Smith", "Mary Jones", "Ronald Archer"], "Assigned To", false, false, true, true),
.switch(false, "Show My Work Orders"),
.filter([0, 2], ["Received", "Started", "Hold", "Transfer", "Completed", "Pending Review", "Rejected"], "Mobile Status"),
],
[
.datePicker(Date(), "Date and Time")
]
]
// This is required for `FUISortFilterViewController` to invoke it to update the UI to show the number of results based on the current sort and filter criteria.
vc.onChangeHandler = { [weak self] values, change in
// Returns the total number of items when no filter criteria have been provided.
if values.isEmpty {
return 20
}
/// your code goes here
return filteredNum
}
// Required.
vc.completionHandler = { [weak self] values, filteredNum in
/// your code goes here
}
let nav = UINavigationController(rootViewController: vc)
vc.modalPresentationStyle = .popover
vc.popoverPresentationController?.barButtonItem = sender
self.present(nav, animated: true)
Note:
The title and subtitle for UINavigationBar and title for the Action button in the bottom UIToolbar can be customized as well.
/// Customize the title and subtitle for `UINavigationBar`. This is optional.
vc.titleAndSubtitleHandler = { filteredResult, totalNum in
("Filter", "Orders \(filteredResult) of \(totalNum)")
}
/// Customize the title for the action button. This is optional.
vc.actionButtonTitleHandler = { filteredResult in
"Show \(filteredResult) orders"
}
FUISortFilterFormDelegate Example:
vc.sortFilterFormDelegate = self
extension YourDelegateClass: FUISortFilterFormDelegate {
func cell(_ vc: FUISortFilterViewController, controlType: FUISortFilterViewController.ControlType, at indexPath: IndexPath) -> UITableViewCell? {
if indexPath == IndexPath(row: 0, section: 8) {
let tableView = vc.tableView
return tableView?.dequeueReusableCell(withIdentifier: "cellId", for: indexPath)
}
return nil
}
func configCell(_ vc: FUISortFilterViewController, controlType: FUISortFilterViewController.ControlType, at indexPath: IndexPath, cell: UITableViewCell) -> UITableViewCell {
if indexPath == IndexPath(row: 0, section: 1) {
if let theCell = cell as? FUIListPickerFormCell {
theCell.isPickerDismissedOnSelection = true
theCell.alwaysShowValueTextOnBottom = true
return theCell
}
}
return cell
}
}
-
Undocumented
See moreDeclaration
Swift
public enum ControlType -
It is the initial state when then button “Reset” is tapped. The default value is the “values”.
Declaration
Swift
@MainActor public var initValues: [[ControlType]] -
2D array of sort and filter criteria. The first dimension of the array is comprised of sections and the second dimension is
ControlTypesfor that section.Declaration
Swift
@MainActor public var values: [[ControlType]] -
Required: the handler to calculate the filtered number of items.
Declaration
Swift
@MainActor public var onChangeHandler: (([[ControlType]], ControlType?) -> Int)? { get set }Parameters
valueThe current values of all sort and filters.
changeThe change sort or filter. This is optional.
Return Value
The filtered number of items.
-
required: The handler to invoke once the Action button is tapped.
Declaration
Swift
@MainActor public var completionHandler: (([[ControlType]], Int) -> Void)?Parameters
valueThe current values of all sort and filters.
filteredNumThe current number of filtered items.
-
The title and subtitle handler for
UINavigationBar. Subtitle is optional. The default handler returns (“Filter”, “Results (filteredNum) of (totalNum)”).Declaration
Swift
@MainActor public var titleAndSubtitleHandler: ((Int, Int) -> (String, String?))Parameters
filteredNumThe current number of filtered items. This can be used in the title or subtitle.
totalNumThe total number of items. This can be used in the title or subtitle.
Return Value
Title and subtitle. Subtitle is optional.
-
Title handler for the Action button. The default handler returns “Show (filteredNum) items”.
Declaration
Swift
@MainActor public var actionButtonTitleHandler: ((Int) -> String)Parameters
filteredNumThe current number of filtered items. This can be used in the title or subtitle.
Return Value
Title for the Action button.
-
delegate to config cells
Declaration
Swift
@MainActor public weak var sortFilterFormDelegate: FUISortFilterFormDelegate? -
Declaration
Swift
@MainActor required public init?(coder: NSCoder) -
Declaration
Swift
@MainActor public override func viewDidLoad() -
Declaration
Swift
@MainActor public override func viewDidAppear(_ animated: Bool) -
Undocumented
Declaration
Swift
@MainActor public override func viewWillAppear(_ animated: Bool) -
Undocumented
Declaration
Swift
@MainActor public override func viewWillDisappear(_ animated: Bool) -
Undocumented
Declaration
Swift
@MainActor public override func viewDidDisappear(_ animated: Bool)
-
Undocumented
Declaration
Swift
@MainActor public override func numberOfSections(in tableView: UITableView) -> Int -
Undocumented
Declaration
Swift
@MainActor public override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? -
Undocumented
Declaration
Swift
@MainActor public override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat -
Undocumented
Declaration
Swift
@MainActor public override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int -
Undocumented
Declaration
Swift
@MainActor public override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell