简体   繁体   English

UISearchController中的“取消”按钮导致SearchBar出现故障

[英]Cancel Button in UISearchController Causes SearchBar Glitch

In viewDidload , I instantiate the UISearchController and add its search bar to the table view's header view, as is standard procedure. viewDidload ,我将实例化UISearchController并将其搜索栏添加到表视图的标题视图中,这是标准过程。

If I tap the search bar and enter some text, results are displayed and I cancel the search here, no problem. 如果我点击搜索栏并输入一些文本,则会显示结果,并且我在此处取消搜索,没问题。

If instead, I select one of the result rows, push into the next screen, pop back and cancel here, the search bar is glitched. 相反,如果我选择结果行之一,则推入下一个屏幕,然后弹出并在此处取消,则搜索栏会出现故障。

Here is my searchController: 这是我的searchController:

// MARK : SearchController ! //

    var searchController : UISearchController!

    var resultsController = UITableViewController()

    ///////////
    override func viewDidLoad() {
        super.viewDidLoad()

        definesPresentationContext = true
        self.resultsController.tableView.dataSource = self
        self.resultsController.tableView.delegate = self
        self.searchController = UISearchController(searchResultsController: self.resultsController)
        self.tableView.tableHeaderView = self.searchController.searchBar
        self.searchController.searchResultsUpdater = self
        self.searchController.dimsBackgroundDuringPresentation = true
        self.searchController.searchBar.sizeToFit()
        self.searchController.searchBar.barTintColor = UIColor.blackColor()
        self.searchController.searchBar.endEditing(true)
        self.searchController.searchBar.placeholder = "חפש ברים"
        self.searchController.hidesNavigationBarDuringPresentation = false
        self.searchController.searchBar.delegate = self

}

Example of Whole Search bar glitching UI : 整个搜索栏故障UI的示例:

在此处输入图片说明

its like the search bar is not the tableHeaderView anymore here and its ruining the tableview cutting last cell and first cell in half. 就像搜索栏不再是tableHeaderView一样,它破坏了tableview将最后一个单元格和第一个单元格减半。

Example of how the tableView looks like regularly : tableView定期显示的示例:

在此处输入图片说明

Thank you in advance! 先感谢您!

After playing with tremendous amount of settings i have managed to find a solution by myself, I have no idea why these specific settings fix the issue but here is what fixed the issue for me : 经过大量的设置后,我设法自己找到了解决方案,我不知道为什么这些特定的设置可以解决此问题,但是以下是为我解决了该问题的原因:

Settings in the attributes inspector: 属性检查器中的设置:

在此处输入图片说明

Settings in viewDidLoad : viewDidLoad中的设置:

    override func viewDidLoad() {
                    super.viewDidLoad()

            //MARK : Fixes SearchBar Bugs

    self.resultsController.edgesForExtendedLayout = .All
    self.searchController.edgesForExtendedLayout = .All            

self.resultsController.extendedLayoutIncludesOpaqueBars = true

// End of Bug Fixes.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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