2017-11-06 6 views
0
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. 

この検索バーを使用しない場合は、UIが表示されます。私がここで間違っていることを教えてください。 UIは、添付された画像のようにうまくいかないと、私が述べたように、ナビゲーション項目に追加しようとした場合ビュー iOS 11でのUISearchBarアライメントの問題

  • ヘッダするUISearchbarを追加した場合の問題の

    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に

    • ですコードで表示されていません
    • 私は検索がアクティブなときに私は別の検索結果のコントローラを使用しているので、私はpreseでアクションを無効にする必要がありますntのコントローラ - どのように私はこれを簡単に達成することができます。
  • 答えて

    0

    私は何が間違っていたのか分かりませんが、私の場合はうまくいきます。

    1. searchController = UISearchControllerを聞かせてfileprivate searchController

      を作成した(searchResultsController::ゼロ)のviewDidLoadで

    2. ():

      searchController.searchResultsUpdater =自己 searchControllerここに私のコードです.obscuresBackgroundDuringPresentation = false searchController.searchBar.placeholder = kSearchPlaceholder searchController.searchBar.scopeButtonTitles = [kCategory、kAuthor、kPicture] searchController.searchBar.delegate =自己 definesPresentationContext =真

      #available IF(IOSの11.0、*){ navigationItem.searchController = searchController }他{ tableView.tableHeaderView = searchController.searchBar }

    そして、それは行ってもいいです。

    関連する問題