gpt4 book ai didi

swift - iOS 11 中的 UISearchBar 对齐问题

转载 作者:行者123 更新时间:2023-11-30 12:01:39 25 4
gpt4 key购买 nike

   I have UITableViewController where i was adding UISearchController searchbar as an headerView and I have changed this to navigationItem.searchcontroller for iOS 11 in iOS 11 searchbar won't appear at all even navigationItem was present.

如果不使用这个搜索栏用户界面就会被折腾。请告诉我我在这里做错了什么。

let  searchController = UISearchController(searchResultsController: vc)
searchController.searchBar.scopeButtonTitles = ["All", "images", "videos", "others"]
searchController.dimsBackgroundDuringPresentation = false
// Don't remove these two lines then search bar alignment issue will raise
self.extendedLayoutIncludesOpaqueBars = true
self.searchController.searchBar.isHidden = false
definesPresentationContext = false
if #available(iOS 11.0, *) {
self.navigationItem.searchController = searchController // not working for me.
searchController?.hidesNavigationBarDuringPresentation = false
navigationItem.hidesSearchBarWhenScrolling = false

} else {
searchController?.hidesNavigationBarDuringPresentation = true
searchController?.searchBar.sizeToFit()
tableView.tableHeaderView = searchController.searchBar
}

searchbar

问题列表是

  • 在 iOS 11 上,如果将 UISearchbar 添加到标题 View ,UI 会作为附加图像出错
  • 如果我尝试添加到代码中提到的导航项,它不会出现
  • 由于我在搜索处于事件状态时使用不同的搜索结果 Controller ,因此我需要禁用当前 Controller 中的操作 - 如何轻松实现此目的。

最佳答案

我不太确定那里出了什么问题,但就我而言,它工作正常。这是我的代码:

  1. 创建了一个 searchController 文件:

    private let searchController = UISearchController(searchResultsController: nil)
  2. viewDidLoad()中:

    searchController.searchResultsUpdater = self
    searchController.obscuresBackgroundDuringPresentation = false
    searchController.searchBar.placeholder = kSearchPlaceholder
    searchController.searchBar.scopeButtonTitles = [kCategory, kAuthor, kPicture]
    searchController.searchBar.delegate = self
    definesPresentationContext = true

    if #available(iOS 11.0, *) {
    navigationItem.searchController = searchController
    } else {
    tableView.tableHeaderView = searchController.searchBar
    }

一切顺利。

关于swift - iOS 11 中的 UISearchBar 对齐问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47143983/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com