FUISearchToSelectViewController
@MainActor
open class FUISearchToSelectViewController : UIViewController, UITableViewDataSource, UITableViewDelegate
A view controller which specializes in managing a tags field and a table view. Selected table view cell will appear in tags field with a designated tag. You can also deselect a table view cell by deleting its designated tag in tags field. In order to make this work, your subclass must implement FUISearchToSelectViewDelegate
delegate.
Components
searchToSelectView
tagsField
tableView
Usage
Subclassing and conforms to delegate. It conforms to UITableViewDataSource
and UITableViewDelegate
by default.
class MyController: FUISearchToSelectViewController, FUiSearchToSelectViewDelegate {}
Override viewDidLoad
and do some setup here
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.register(FUIObjectTableViewCell.self, forCellReuseIdentifier: FUIObjectTableViewCell.reuseIdentifier)
self.tableView.register(FUITableViewHeaderFooterView.self, forHeaderFooterViewReuseIdentifier: FUITableViewHeaderFooterView.reuseIdentifier)
self.tableView.rowHeight = UITableView.automaticDimension
self.tableView.estimatedRowHeight = 50
// ...
}
Implement dataSource
and delegate methods
// Define data model.
var objects: [ModelObj] = []
// UITableView dataSource and delegate methods
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return objects.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: FUIObjectTableViewCell.reuseIdentifier, for: indexPath) as! FUIObjectTableViewCell
let model = objects[indexPath.row]
cell.isMomentarySelection = false
cell.selectionStyle = .none
cell.detailImage = model.image
cell.detailImageView.isCircular = true
cell.headlineText = model.headline
cell.subheadlineText = model.subheadline
cell.footnoteText = model.footnote
return cell
}
// FUISearchtoSelectViewControllerDelegate delegate
func searchToSelectView(_ searchToSelectView: FUISearchToSelectView, uuidForItemAt indexPath: IndexPath) -> String? {
let obj = objects[indexPath.row]
return obj.uuid
}
func searchToSelectView(_ searchToSelectView: FUISearchToSelectView, tagTitleFor itemUUID: String) -> String? {
if let obj = objects.filter ({ $0.uuid == itemUUID }).first {
return obj.headline
}
return nil
}
Note
Developer is responsible for updating selectedUUIDs
after data changes to make sure all selected UUIDs are still valid.
Theming
Supported class paths:
fdlFUISearchToSelectViewController_searchToSelectView {}
fdlFUISearchToSelectViewController_tableView {}
fdlFUISearchToSelectViewController_tagsField {}
Supported TagsField
attributes:
tint-color (Color)
background-color (Color)
content-insets (Box)
font-color { -placeholder } (Color)
font-name (FontName)
font-style (UIFontTextStyle)
font-size (Number)
text-line-clamp (Integer)
line-spacing (Float)
tag-spacing (Float)
tag-delimiter (String)
Supported Tag
attributes:
tag-font-color { -selected } (Color)
tag-background-color { -selected } (Color)
tag-content-insets (Box)
Supported ImageView
attributes:
search-icon-image (Image)
search-icon-image-tint-color (Color)
-
The tags field of the controller.
Declaration
Swift
@MainActor public var tagsField: FUISearchTagsField { get }
-
The table view of the controller.
Declaration
Swift
@MainActor public var tableView: UITableView! { get }
-
The default implementation of this method does nothing. Subclasses should override it to perform additional actions whenever selected uuids changes.
Declaration
Swift
@MainActor open func selectedUUIDsDidChange()
-
UUIDs for selected cells. If you have multiple uuid to append to this array, batch them up into one operation instead of appending one at a time.
Declaration
Swift
@MainActor open var selectedUUIDs: [String] { get set }
-
The object that acts as the delegate of the contoller’s searchToSelectView.
Declaration
Swift
@MainActor public weak var searchtoSelectViewDelegate: FUISearchToSelectViewDelegate?