FUIListPickerTableViewController
@MainActor
open class FUIListPickerTableViewController : UITableViewController, UISearchResultsUpdating, UISearchBarDelegate
extension FUIListPickerTableViewController: FUIBarcodeScanViewControllerDelegate
extension FUIListPickerTableViewController: UISheetPresentationControllerDelegate
This FUIListPickerTableViewController is to show a list of table view cells to let user select one of the cell.
Developer needs to provide implementation of FUIListPickerDataSource, and FUIListPickerSearchResultsUpdating
if search is enabled, in order to use FUIListPickerTableViewController.
If the isDismissedOnSelection property is set to true, and the allowsMultipleSelection property is set to false, then when user selected one cell by tapping the displayed
cell, the onSelectionHandler property will be invoked to notify the user selection. The table view will then be dismissed.
There will be a “Done” button shown in the navigation bar if the isDismissedOnSelection property is set to false or the allowsMultipleSelection property is set to true.
The onSelectionHandler property will be invoked after user tapped the “Done” button if the allowsMultipleSelection property is set to false,
or the onMultipleSelectionHandler property will be invoked if the allowsMultipleSelection property is set to true. Then the table view will be dismissed.
There will be a “Select All” button in the “All” section header, if multiple selections is allowed and not all items are selected. All items are selected when the “Select All” button is tapped. Once all items are selected, the button title will change to “Deselect All”. All items are de-selected when “Deselect All” button is tapped.
Also, a “Deselect All” button will be in the “Selected” section header when multiple selections is allowed. The “Selected” section will appear if the items in the list could not be displayed in one screen, and there are one or more items selected. All selected items will be de-selected when “Deselect All” button is tapped.
Here is a code snippet of a typical usage:
let listPickerTableViewController = createInstanceFromStoryboard()
var listPicker = listPickerTableViewController.listPicker
listPicker.title = "Magic School"
listPicker.register(FUIObjectTableViewCell.self, forCellReuseIdentifier: FUIObjectTableViewCell.reuseIdentifier)
listPicker.dataSource = self.objectCellListPickerDataSource
listPicker.prompt = "Select One"
listPicker.estimatedRowHeight = 98
listPicker.isSearchEnabled = true
listPicker.searchResultsUpdating = self.objectCellListPickerDataSource
listPicker.isBarcodeScannerEnabled = true
listPicker.barcodeScanMode = .all
listPicker.barcodeScanResultTransformer = { (scanString) -> String in
return "S"
}
listPickerTableViewController.onSelectionHandler = {
self.select1Result.text = self.objectCellListPickerDataSource.descriptionForSelectedItems(at: [$0])
}
listPickerTableViewController.showsCancelButton = true
listPickerTableViewController.isDismissedOnSelection = false
// Select item at index 4 as default, which is the 5th item.
listPickerTableViewController.selectItem(4)
let navController = UINavigationController(rootViewController: listPickerTableViewController)
self.present(navController, animated: true, completion: nil)
Theming
Supported style classes
fdlFUIListPickerTableViewController
fdlFUIListPickerTableViewController_cancelItem
fdlFUIListPickerTableViewController_sectionHeaderTitleLabel
fdlFUIListPickerTableViewController_listTextLabel
-
Creates a
FUIListPickerTableViewControllerobject from storyboard.Declaration
Swift
@available(*, deprecated, message: "Please use init(style:﹚ instead") @MainActor public class func createInstanceFromStoryboard() -> FUIListPickerTableViewControllerReturn Value
The instantiated
FUIListPickerTableViewControllerobject. -
This is the developer implementation of the handler when the scan button is tapped.
If the value is set to nil, the default barcode scanner will be used.
Declaration
Swift
@MainActor public var customScanHandler: ((UISearchBar) -> Void)? -
The effective
UINavigationController.Developer could set this to the
UINavigationControllerfor this view controller. If developer did not set this value, theUINavigationControllerof this view controller will be returned if it is not nil. Otherwise, the rootUINavigationControllerfrom thekeyWindow, if any, will be returned.Declaration
Swift
@MainActor public var effectiveNavigationController: UINavigationController? { get set } -
Customization handler for section header view.
Developers can use this handler to customize the section header view. The first parameter is the section index, the second parameter is the section header view, the third parameter indicates whether this is a selected section, and the fourth parameter is the type of the action button.
Declaration
Swift
@MainActor public var sectionHeaderCustomizationHandler: ((Int, FUIListPickerHeaderView, Bool, FUIListPickerSectionHeaderButtonType) -> Void)? -
This property indicates whether the “Cancel” button is shown in the search bar or not when search is active.
The default is
true.Declaration
Swift
@MainActor public var showsCancelButtonOnSearchBar: Bool -
The
FUIListPickerfor this controller.Declaration
Swift
@MainActor public var listPicker: FUIListPicker -
This property indicates whether the selection mark is on the leading side or not.
The default value is
false, meaning that there will be a check mark on the trailing side of the cell for a selected item.Otherwise, when the value is
true, there will be an empty circle on the leading side of the cell for a unselected item, and a circle with a check mark in the center for a selected item.Declaration
Swift
@MainActor open var usesLeadingSelectionStyle: Bool -
This property indicates whether an anchor button is to be displayed.
The anchor button floats on top of the selection table view. When tapped, it takes the user to the top of the list.
- The anchor button is only available in full model sheet view.
- It will only appear if a selection is made and if the selected section is outside of the visible area.
- It has a number indicating the number of items selected.
The default is
true.Declaration
Swift
@MainActor open var showsAnchorButton: Bool -
The custom title format for the anchor button.
If this property is
nil, the default title format is localized “Selected (%d)”.Declaration
Swift
@MainActor open var anchorButtonTitleFormat: String? -
This property indicates whether an alert controller will be displayed when the user dismisses the selection table view without tapping the “Cancel” or “Apply” buttons in modal presentation.
The default is
true.Declaration
Swift
@MainActor open var showsAlertOnDismiss: Bool -
The custom message of the alert when it is dismissed.
If this is
nil, the default is the localized string: “Are you sure you want to discard your selections?”.Declaration
Swift
@MainActor open var alertMessage: String? -
The custom title for the “Discard Changes” button in the dismiss alert.
If this is
nil, the default is the localized string: “Discard Changes”.Declaration
Swift
@MainActor open var discardChangesActionTitle: String? -
The custom title for the “Keep Editing” button in the dismiss alert.
If this is
nil, the default is the localized string: “Keep Editing”.Declaration
Swift
@MainActor open var keepEditingActionTitle: String? -
This handler closure is invoked when the selection is done and this
FUIListPickerFormTableViewControlleris presented from aFUIListPickerFormCell.The default is
nil, in which case, the invokingFUIListPickerFormCellwill be reloaded from itstableViewusing thetableView.reloadRowsAPI when the selection is done. Otherwise, the handler closure is invoked.Note
The developer needs to set this property when thedataSourceof thetableViewhosting theFUIListPickerFormCellis anUITableViewDiffableDataSourceinstance. Otherwise, a crash will occur.The implementation of this handler should at least reload the
FUIListPickerFormCellto reflect the selections.Declaration
Swift
@MainActor open var didFinishSelectionHandler: (() -> Void)? -
This property indicates whether to show the “All” section or not.
The default is
true.Declaration
Swift
@MainActor open var showsAllSectionHeader: Bool -
Initialize a table view controller to manage a table view with grouped style
Declaration
Swift
@MainActor public convenience init() -
Initialize a table view controller to manage a table view with a given style.
Declaration
Swift
@MainActor public override init(style: UITableView.Style)Parameters
styleA constant that specifies the style of table view that the controller object is to manage (UITableView.Style.plain, UITableView.Style.grouped or UITableView.Style.insetGrouped).
-
Undocumented
Declaration
Swift
@MainActor required public init?(coder: NSCoder) -
:nodoc
Declaration
Swift
@MainActor open override func viewIsAppearing(_ animated: Bool) -
Undocumented
Declaration
Swift
@MainActor open override func viewDidDisappear(_ animated: Bool) -
The block is to be invoked when selection is made with
isDataSourceRequiringUniqueIdentifiersfalse andallowsMultipleSelectionfalse.Declaration
Swift
@MainActor public var onSelectionHandler: ((Int) -> Void)? -
The block is to be invoked when selection is made with
isDataSourceRequiringUniqueIdentifiersfalse andallowsMultipleSelectiontrue.Declaration
Swift
@MainActor public var onMultipleSelectionHandler: (([Int]) -> Void)? -
The block is to be invoked when selection is made with
isDataSourceRequiringUniqueIdentifierstrue andallowsMultipleSelectionfalse.Declaration
Swift
@MainActor public var onUuidSelectionHandler: ((String) -> Void)? -
The block is to be invoked when selection is made with
isDataSourceRequiringUniqueIdentifierstrue andallowsMultipleSelectiontrue.Declaration
Swift
@MainActor public var onUuidMultipleSelectionHandler: (([String]) -> Void)? -
A boolean value indicating to show the “Cancel” button or not.
Default is false.
Declaration
Swift
@MainActor public var showsCancelButton: Bool { get set } -
The “Cancel” button on the navigation bar.
Declaration
Swift
@MainActor public var cancelBarButtonItem: UIBarButtonItem! -
If this property is true, this list picker table view will be dismissed once user makes the selection.
If this is false, there will be a “Done” button in addition to a “Cancle” button. User needs to tap the “Done” button to dismiss the list picker table view. The
onSelectionHandlerwill then be invoked. The default is true.This property is ignored if
allowsMultipleSelectionis true.Declaration
Swift
@MainActor public var isDismissedOnSelection: Bool -
Indicates if user can select multiple values. Default is false, meaning by default user may select only one value.
Declaration
Swift
@MainActor public var allowsMultipleSelection: Bool { get set } -
Indicates if empty selection is allowed.
The default value is false, meaning by default user must select at least one item.
Declaration
Swift
@MainActor public var allowsEmptySelection: Bool -
A view to be displayed when there are no items.
The view will be added as a
subviewof the controller’stableView.Declaration
Swift
@MainActor public var emptyStateView: UIView?
-
Adjusts the tableview’s
contentOffsetwhen search is canceled.The default is
true. When search is canceled, iOS sometimes may move thecontentOffsetof the tableview to a value whick is not desirable. Set this property to true to adjust thecontentOffsetback to top.Or, developer can set this to
falseto just use the standard iOS behavior.Declaration
Swift
@MainActor public var adjustsContentOffsetOnCancelSearch: Bool -
Undocumented
Declaration
Swift
@MainActor open override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat
-
Select an item with an index programatically.
This is to be used to pre-select an item before presenting this controller. Note that this function does nothing when the
isDataSourceRequiringUniqueIdentifiersproperty of theFUIListPickeris true.Declaration
Swift
@MainActor public func selectItem(_ index: Int)Parameters
indexThe index for the selected item in the list.
-
Deselect items programmatically. Note that this function always returns false when the
isDataSourceRequiringUniqueIdentifiersproperty of theFUIListPickeristrue. Deselecting all selected items is not allowed ifallowsEmptySelectionis set tofalse. Also the indexes which are not pre-selected will be ignored.Declaration
Swift
@discardableResult @MainActor public func deselectItems(_ indexes: [Int]) -> BoolParameters
indexesIndexes of items to be deselected.
Return Value
A Boolean value indicating whether items are deselected successfully.
-
Select an item using unique identifier programatically.
This is to be used to pre-select an item before presenting this controller. Note that this function does nothing when the
isDataSourceRequiringUniqueIdentifiersproperty of theFUIListPickeris false.Declaration
Swift
@MainActor public func selectItem(_ uniqueIdentifier: String)Parameters
uniqueIdentifierThe unique identifier for the selected item.
-
Deselect items programmatically. Note that this function always returns false when the
isDataSourceRequiringUniqueIdentifiersproperty of theFUIListPickerisfalse. Deselecting all selected items is not allowed ifallowsEmptySelectionis set tofalse. Also the identifiers which are not pre-selected will be ignored.Declaration
Swift
@discardableResult @MainActor public func deselectItems(_ uniqueIdentifiers: [String]) -> BoolParameters
uniqueIdentifiersUnique identifiers of items to be deselected.
Return Value
A Boolean value indicating whether items are deselected successfully.
-
Enable the built-in barcode scanner in List Picker
Declaration
Swift
@MainActor public func showDefaultBarcodeScanner()