iOS 13 - When Search Active Push to Other Vc Then That Vc Uitableview Goes Under the Navigationbar in Swift 4

iOS 13 strange search controller gap

Setting

extendedLayoutIncludesOpaqueBars = true

in the UIViewController used to show the search results, fixed the issue for me.

Broken UISearchBar animation embedded in NavigationItem

It looks like Apple still needs to iron out the use of the UISearchBar in the new large title style. If the UIViewController you push to doesn't have its navigationItem.searchController set, the animation works fine. When navigating between two instances of UIViewController that both have a searchController set, you get the issue you describe where the height of the navigation bar jumps.

You can solve (work around) the problem by creating the UISearchController every time viewDidAppear gets called (instead of creating it in loadView) and setting navigationItem.searchController to nil on viewDidDisappear.

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

DispatchQueue.main.async {
let stvc = UITableViewController()
stvc.tableView.dataSource = self

let sc = UISearchController(searchResultsController: stvc)
sc.searchResultsUpdater = self
self.navigationItem.searchController = sc
}
}

override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)

self.navigationItem.searchController = nil
}

The reason for the asynchronous dispatch is that when setting the navigationItem.searchController inline in the viewDidAppear method, an exception is raised:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Only one palette with a top boundary edge can be active outside of a transition. Current active palette is <_UINavigationControllerManagedSearchPalette: 0x7fad67117e80; frame = (0 116; 414 0); layer = <CALayer: 0x60400002c8e0>>'

I know this is only a work around, but hopefully this will help you for now, until Apple solves the issue with navigating between two view controllers that both have a UISearchController set on their navigationItem.

Navigation bar issue when search is active and push to next view controller

You can fix this issue by making search controller inactive, then navigate to your details view controller after some delay.

Try following code in you didSelect method which will help you to hide navigation bar when search controller is active.

searchController.isActive = false

DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.navigationController?.navigationBar.isHidden = true
self.navigationController?.isNavigationBarHidden = true
self.navigationController?.pushViewController(<YourViewController>, animated: true)
}

You must required delay to navigate otherwise it's give you warning in console regarding navigation controller presentation process.

So, this code first make your search controller inactive and then navigate to your next view controller.



Related Topics



Leave a reply



Submit