【发布时间】:2014-11-07 16:21:37
【问题描述】:
如何实现:我有一个带有搜索图标的 UIBarButtonItem,点击它后,我想在导航栏中显示搜索栏,点击搜索栏中的取消按钮,我想在没有搜索的情况下显示导航栏IOS 7 日历应用中的按钮和标题。
【问题讨论】:
如何实现:我有一个带有搜索图标的 UIBarButtonItem,点击它后,我想在导航栏中显示搜索栏,点击搜索栏中的取消按钮,我想在没有搜索的情况下显示导航栏IOS 7 日历应用中的按钮和标题。
【问题讨论】:
为您的搜索按钮设置一个操作以显示UISearchController。请参阅 Apple 的 UICatalog sample code 中的 Search > Present Over Navigation Bar 演示:
- (IBAction)searchButtonClicked:(UIBarButtonItem *)sender {
// Create the search results view controller and use it for the UISearchController.
AAPLSearchResultsViewController *searchResultsController = [self.storyboard instantiateViewControllerWithIdentifier:AAPLSearchResultsViewControllerStoryboardIdentifier];
// Create the search controller and make it perform the results updating.
self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
self.searchController.searchResultsUpdater = searchResultsController;
self.searchController.hidesNavigationBarDuringPresentation = NO;
// Present the view controller.
[self presentViewController:self.searchController animated:YES completion:nil];
}
【讨论】: