Eureka
Eureka copied to clipboard
Why does Eureka's UITableView scroll offset end up behind the UISearchController when returning to its view?
Using: Eureka (5.0.0), Xcode 11.2
I'm having difficulty figuring out why Eureka's TableView cells end up behind the search bar. I haven't adjusted any constraints either.
My setup:
override func viewDidLoad() {
// Setup Eureka's UITableViewStyle to `Plain` (like 'Contacts' app)
// https://github.com/xmartlabs/Eureka/issues/218
if tableView == nil {
tableView = UITableView(frame: view.bounds, style: UITableView.Style.plain)
tableView?.autoresizingMask = UIView.AutoresizingMask.flexibleWidth.union(.flexibleHeight)
tableView.cellLayoutMarginsFollowReadableWidth = false
}
// *now* call super.
super.viewDidLoad()
// Add search bar
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false
definesPresentationContext = true
// Place the search bar in the navigation bar.
self.navigationItem.searchController = self.searchController
self.navigationItem.hidesSearchBarWhenScrolling = false
}
Trying to adjust the constraints doesn't help either.
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
self.tableView.snp.remakeConstraints { make -> Void in
make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top)
make.leading.equalTo(self.view.safeAreaLayoutGuide.snp.leading)
make.trailing.equalTo(self.view.safeAreaLayoutGuide.snp.trailing)
make.bottom.equalToSuperview()
}
}
After countless more testing on iOS 12 and 13, because I was getting different UX results, I discovered this: https://stackoverflow.com/a/57861125/7599
Which results in: (using Snapkit)
extendedLayoutIncludesOpaqueBars = true
self.tableView.snp.remakeConstraints { make -> Void in
make.top.equalToSuperview()
make.leading.equalTo(self.view.safeAreaLayoutGuide.snp.leading)
make.trailing.equalTo(self.view.safeAreaLayoutGuide.snp.trailing)
make.bottom.equalToSuperview()
}
I think this is an issue of how you arrange the tableView, which is something Eureka does not do. You should not place the tableView under other views. It might be easier to do it from a Storyboard