如何在Apple的日历应用程序中显示/隐藏导航栏(iOS 8)中的搜索栏?

时间:2014-10-24 23:21:52

标签: uibarbuttonitem searchbar

如何实现:我有一个带有搜索图标的UIBarButtonItem,点击它之后,我想在导航栏中显示搜索栏,然后点击搜索栏中的取消按钮,我想显示导航栏而不搜索和按钮和标题,如IOS 7日历应用程序。

1 个答案:

答案 0 :(得分:8)

为搜索按钮设置操作以显示UISearchController。请参阅Search> Apple UICatalog sample code中的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];
}