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