2017-11-06 5 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가 작동합니다. 제가 여기서 뭘 잘못하고 있는지 제안 해주세요. 언급 한 바와 같이 내가 탐색 항목에 추가하려고하면보기 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

    목록은

    UI와 아이폰 OS (11)에
    • 첨부 이미지로 잘못 코드에 나타나지 않습니다
    • 검색이 활성화되어있을 때 다른 검색 결과 컨트롤러를 사용하고 있기 때문에 prese에서 작업을 비활성화해야합니다. NT 컨트롤러 - 어떻게하면 쉽게 얻을 수 있습니다.
  • 답변

    0

    나는 무엇이 잘못되었는지는 모르지만 제 경우에는 정상적으로 작동합니다.

    1. searchController = UISearchController하자 fileprivate searchController

      을 만든 (searchResultsController : 무기 호)의 viewDidLoad에서

    2. () :

      searchController.searchResultsUpdater = 자기 searchController 여기 내 코드입니다 .obscuresBackgroundDuringPresentation = false searchController.searchBar.placeholder = kSearchPlaceholder,210의 searchController.searchBar.scopeButtonTitles = kCategory, kAuthor, kPicture] searchController.searchBar.delegate = 자기 definesPresentationContext = TRUE

      경우 #available IOS (11.0 *) = { navigationItem.searchController searchController 한다} else { tableView.tableHeaderView = searchController.searchBar }

    그리고 그것은 갈 수 있습니다.