显示搜索结果时,如何避免搜索栏和表格视图之间出现奇怪的间隙?

时间:2018-08-30 14:48:36

标签: ios swift xcode

检查:Screenshot

我尝试了所有相关问题的解决方案。但是他们没有一个真正的帮助。 当搜索栏显示结果时,表格视图和搜索栏之间出现了奇怪的间隙。 帮助我找出我的代码出了什么问题: UITableViewController, UISearchBarDelegate, UISearchResultsUpdating

中的视图控制器子类
var searchController = UISearchController()
var resultsController = UITableViewController()
var refreshController = UIRefreshControl()

in override : 

 configureSearchController()
 resultsController.tableView.delegate = self
 resultsController.tableView.dataSource = self
 refreshController.attributedTitle = NSAttributedString(string: "")
 refreshController.addTarget(self, action: #selector(refreshSelector), for: .valueChanged)
 tableView.addSubview(refreshController)
 searchController.searchBar.delegate = self
 automaticallyAdjustsScrollViewInsets = false
 definesPresentationContext = true



@objc func refreshSelector()
    {
        if(!searchLoaded)
        {
            searchLoaded = true

            self.tableView.tableHeaderView = searchController.searchBar

            self.navigationItem.rightBarButtonItem = nil
            print( "Got ya")
        }
        refreshController.endRefreshing()

    }


func configureSearchController ()
    {
        searchController = UISearchController(searchResultsController: resultsController)
        searchController.searchResultsUpdater = self

        searchController.searchBar.layer.borderWidth = 1;

        searchController.searchBar.barTintColor = UIColor.searchBarBackgroundGrey()
        searchController.searchBar.layer.borderColor = UIColor.searchBarBackgroundGrey().cgColor
        self.navigationController?.navigationBar.shadowImage = UIImage()



    }

部署目标已设置为9.3

0 个答案:

没有答案