Search To Select View Controller¶
FUISearchToSelectViewController¶
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¶
searchToSelectViewtagsFieldtableView
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)
#if swift(>=4.2)
self.tableView.rowHeight = UITableView.automaticDimension
#else
self.tableView.rowHeight = UITableViewAutomaticDimension
#endif
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
selectedUUIDsafter data changes to make sure all selected UUIDs are still valid.
Theming¶
Supported class paths:
1 2 3 | |
Supported TagsField attributes:
1 2 3 4 5 6 7 8 9 10 11 | |
Supported Tag attributes:
1 2 3 | |
Supported ImageView attributes:
1 2 | |