0

私はUIViewcontrollerでsearchControllerを表示しようとしています。 これは問題なく動作しますが、何かを書き込もうとすると検索コントローラが表示されません。SearchController自動的に非表示

私のコードは次の通りである:

class tempVC: UIViewController,UISearchBarDelegate,UISearchResultsUpdating { 

    let searchController = UISearchController(searchResultsController: nil) 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     searchController.searchResultsUpdater = self 
     searchController.searchBar.delegate = self 
     searchController.searchBar.placeholder = "Enter name here..." 
     definesPresentationContext = true 
     searchController.searchBar.sizeToFit() 
     searchController.dimsBackgroundDuringPresentation = false 
     searchController.hidesNavigationBarDuringPresentation=false 
     //navigationItem.titleView = searchController.searchBar 
     searchController.searchBar.frame=CGRectMake(0, 64, 320, 44) 
     self.view.addSubview(searchController.searchBar) 
    } 


    // MARK: - UISearchResultsUpdating Delegate 
    func updateSearchResultsForSearchController(searchController: UISearchController) { 
     // let searchBar = searchController.searchBar 
     //let scope = searchBar.scopeButtonTitles![searchBar.selectedScopeButtonIndex] 
     //filterContentForSearchText(searchController.searchBar.text!, scope: scope) 
     print("update") 
    } 

} 

は、この問題を解決するために私を助けてください。

答えて

0

クラスtempVCありがとう:あなたの答えの変化である何のUIViewController、UISearchBarDelegate、UISearchResultsUpdating {

let searchController = UISearchController(searchResultsController: nil) 

override func viewDidLoad() { 
    super.viewDidLoad() 

    searchController.searchResultsUpdater = self 
    searchController.searchBar.delegate = self 
    searchController.searchBar.placeholder = "Enter name here..." 
    definesPresentationContext = true 
    searchController.searchBar.sizeToFit() 
    searchController.dimsBackgroundDuringPresentation = false 
    searchController.hidesNavigationBarDuringPresentation=false 
    //navigationItem.titleView = searchController.searchBar 
    searchController.searchBar.frame=CGRectMake(0, 64, 320, 44) 
    self.view.addSubview(searchController.searchBar) 
} 


// MARK: - UISearchResultsUpdating Delegate 
func updateSearchResultsForSearchController(searchController: UISearchController) { 
    // let searchBar = searchController.searchBar 
    //let scope = searchBar.scopeButtonTitles![searchBar.selectedScopeButtonIndex] 
    //filterContentForSearchText(searchController.searchBar.text!, scope: scope) 
    print("update") 
} 

}

+0

を? –

関連する問題