Mar*_*rke 4 objective-c uinavigationcontroller uisearchbar ios
我认为标题是非常自我解释的.我有一个嵌入在导航控制器中的tableView,并希望在导航栏中添加一个搜索栏.我认为在iOS 9中有关于搜索栏控制器的东西发生了变化,所以请记住这必须适用于iOS 9.这就是我所拥有的.毫无疑问,这是错误的.
UISearchController *searchController = [[UISearchController alloc]init];
self.searchController.searchBar.barTintColor = [UIColor whiteColor];
[self.navigationController addChildViewController:searchController];
Run Code Online (Sandbox Code Playgroud)
//This method has deprecated in ios 8. So, before ios 8 you can use this.
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
[searchBar sizeToFit];
UISearchDisplayController *searchDisplayController= [[UISearchDisplayController alloc] initWithSearchBar:searchBar
contentsController:self];
self.searchDisplayController.searchResultsDelegate = self;
self.searchDisplayController.searchResultsDataSource = self;
self.searchDisplayController.delegate = self;
self.navigationItem.titleView = searchDisplayController.searchBar;
Run Code Online (Sandbox Code Playgroud)
//对于ios8/ios9,请使用以下代码
UISearchController *searchController = [[UISearchController alloc] initWithSearchResultsController:self];
// Use the current view controller to update the search results.
searchController.searchResultsUpdater = self;
// Install the search bar as the table header.
self.navigationItem.titleView = searchController.searchBar;
// It is usually good to set the presentation context.
self.definesPresentationContext = YES;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15525 次 |
| 最近记录: |