UISearchDisplayController is deprecated in IOS8.0, then how to init it?

做~自己de王妃 提交于 2019-12-08 12:23:10

问题


UISearchDisplayController is deprecated in IOS8.0, and recommended to use UISearchController instead.

Then How to use the new **API** to implement the flowing :

(from Beginning IOS7 Development Exploring the IOS SDK)

UISearchBar *searchBar = [[UISearchBar alloc]
                              initWithFrame:CGRectMake(0, 0, 320, 44)];
tableView.tableHeaderView = searchBar;
searchContoller = [[UISearchDisplayController alloc]
                     initWithSearchBar:searchBar
                     contentsController:self];
searchController.delegate = self;
searchController.searchResultsDataSource = self;

You know, the API in UISearchController is different, then how to do ?


回答1:


From APPLE DOCUMENTATION:

searchController = [[UISearchController alloc] initWithSearchResultsController:nil];

searchController.searchResultsUpdater = self;

searchController.dimsBackgroundDuringPresentation = NO;

searchController.hidesNavigationBarDuringPresentation = NO;

searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 44.0);

self.tableView.tableHeaderView = self.searchController.searchBar;

Check this SAMPLE PROJECT on UISearchController.




回答2:


Here is a sample project that replaces the UISearchDisplayController with UISearchController based off the Vea Software tutorial video found on youtube.

https://github.com/2015HuntMJ/UISearchController

NOTE: the above project uses swift



来源:https://stackoverflow.com/questions/27309993/uisearchdisplaycontroller-is-deprecated-in-ios8-0-then-how-to-init-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!