简体   繁体   中英

UITableView cells overlap search bar view set as searchController for NavigationBar

I have a UISearchController configured as searchController for navigation bar. I have following setup.

let searchController = UISearchController(searchResultsController: nil)
searchController.hidesNavigationBarDuringPresentation = true
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.placeholder = LocalisedStrings.searchChannels
searchController.searchBar.searchBarStyle = .minimal
searchController.searchBar.delegate = self
navigationItem.hidesSearchBarWhenScrolling = false
navigationItem.searchController = searchController

I have a UITableView as child view for the ViewController's view as follows:

func setupView() {
    extendedLayoutIncludesOpaqueBars = true
    view.backgroundColor = secondarySurfaceColor
    view.addSubview(channelsTV)
    view.addSubview(emptyView)
    
    NSLayoutConstraint.activate([
        channelsTV.leadingAnchor.constraint(equalTo: view.leadingAnchor),
        channelsTV.topAnchor.constraint(equalTo: view.topAnchor),
        channelsTV.trailingAnchor.constraint(equalTo: view.trailingAnchor),
        channelsTV.bottomAnchor.constraint(equalTo: view.bottomAnchor),
        
        emptyView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
        emptyViewCenterYAnchorConstraint,
    ])
}

I am facing the following issue of UITableView items visible under the search controller for minor scrolls and is normal during normal up/down scroll sling.

在此处输入图像描述

Desired behavior is that the tableView cells should not overlap the Search Bar and Navigation bar. But the navigation bar should collapse from large title to small title when tableView is scrolled. Is there any way? Help on this is much-appreciated thanks in advance. Please comment if you'd need some more details.

try this trick:

view.addSubview(UIView()) // To prevent the large tile nav bar from collapsing

I ignore the reason but this breaks the link between your the UIScrollView and the nav bar... This probably solve your issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM