Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在显示搜索结果时,如何避免搜索栏和表视图之间出现奇怪的间隙?_Ios_Swift_Xcode - Fatal编程技术网

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

Ios 在显示搜索结果时,如何避免搜索栏和表视图之间出现奇怪的间隙?,ios,swift,xcode,Ios,Swift,Xcode,检查: 我试图解决所有相关问题。然而,他们没有一个人真正起到帮助作用。 当搜索栏显示结果时,我发现表视图和搜索栏之间有一个奇怪的间隙。 帮助我找出我的代码有什么问题: 视图控制器子类来自UITableViewController、UISearchBarDelegate、UISearchResultsUpdating var searchController = UISearchController() var resultsController = UITableViewController()

检查:

我试图解决所有相关问题。然而,他们没有一个人真正起到帮助作用。 当搜索栏显示结果时,我发现表视图和搜索栏之间有一个奇怪的间隙。 帮助我找出我的代码有什么问题: 视图控制器子类来自
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

能否提供屏幕截图?也是iOS目标版本。您是否尝试取消选中故事板上的“调整滚动视图插入”选项?@inokey,已添加。@DanielAmarante,是的,我尝试过。唯一想到的是tableView样式属性。如果您有一个分组的tableView,则此间隙来自节标题大小。尝试将标题大小设置为0.1,然后查看问题是否仍然存在。