UISearchController 的用法[點擊搜索框,自動到頂部]


//在ViewDidLoad里面如下代碼

self.searchViewController = [[UISearchController alloc]initWithSearchResultsController:nil]; self.searchViewController.active = NO; self.searchViewController.dimsBackgroundDuringPresentation = NO; self.searchViewController.hidesNavigationBarDuringPresentation = YES; [self.searchViewController.searchBar sizeToFit]; self.searchViewController.searchBar.barTintColor = kALittleGray; //設置顯示搜索結果的控制器 self.searchViewController.searchResultsUpdater = self; //協議(UISearchResultsUpdating) self.searchViewController.delegate = self; self.tableView.tableHeaderView = self.searchViewController.searchBar; self.searchViewController.searchBar.keyboardType = UIKeyboardAppearanceDefault; self.searchViewController.searchBar.placeholder = @"請輸入城市關鍵字";

遵守協議:

UISearchBarDelegate,UISearchControllerDelegate,UISearchResultsUpdating

 

 

 

 

#pragma mark - other delegate

- (void)updateSearchResultsForSearchController:(UISearchController *)searchController{

    

   

}

 

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar

{

    return YES;

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM