You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi!
I created a page containing a searchBar and a tableView.
When the keyboard appears, the page goes up and the top comes out of the screen.
I have tried several things, but I am unable to reduce the size of the tableView so that the search bar stays visible.
Here is my code, simplified, to use and try as is:
import UIKit
import BLTNBoard
class HistoricPage: FeedbackPageBLTNItem {
fileprivate var tableView: UITableView?
fileprivate var searchBar: UISearchBar?
fileprivate var numberOfItems: Int = 20
override func tearDown() {
super.tearDown()
tableView?.dataSource = nil
tableView?.delegate = nil
searchBar?.delegate = nil
}
override func makeViewsUnderTitle(with interfaceBuilder: BLTNInterfaceBuilder) -> [UIView]? {
let stack = interfaceBuilder.makeGroupStack(spacing: 0)
stack.alignment = .fill
stack.distribution = .fill
let searchBar = UISearchBar(frame: .zero)
searchBar.searchBarStyle = .minimal
let searchBarWrapper = interfaceBuilder.wrapView(searchBar, width: nil, height: nil, position: .pinnedToEdges)
self.searchBar = searchBar
let tableView = UITableView(frame: .zero, style: .plain)
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "CellIdentifier")
tableView.rowHeight = 38
let tableWrapper = interfaceBuilder.wrapView(tableView, width: nil, height: NSNumber(value: numberOfItems * Int(tableView.rowHeight)), position: .pinnedToEdges)
self.tableView = tableView
tableView.dataSource = self
tableView.delegate = self
searchBar.delegate = self
stack.addArrangedSubview(searchBarWrapper)
stack.addArrangedSubview(tableWrapper)
return [stack]
}
}
extension HistoricPage: UITableViewDataSource, UITableViewDelegate {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return numberOfItems
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CellIdentifier", for: indexPath)
cell.textLabel?.text = String(indexPath.row+1)
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.searchBar?.resignFirstResponder()
}
}
extension HistoricPage: UISearchBarDelegate {
func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
// Something to do here to resize tableView/tableWrapper?
}
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
if let text = searchBar.text, let numberOfItems = Int(text) {
tableView?.setContentOffset(.zero, animated: true) // scroll to top
self.numberOfItems = numberOfItems
self.tableView?.reloadData()
// Something to do here to resize tableView/tableWrapper according to number of items?
}
}
}
Thanks for the help anyone can give me 🙏
The text was updated successfully, but these errors were encountered:
Hi!
I created a page containing a searchBar and a tableView.
When the keyboard appears, the page goes up and the top comes out of the screen.
I have tried several things, but I am unable to reduce the size of the tableView so that the search bar stays visible.
Here is my code, simplified, to use and try as is:
Thanks for the help anyone can give me 🙏
The text was updated successfully, but these errors were encountered: