How to show/hide a search bar inside a navigation bar (iOS 8) as in Apple's Calendar app?

孤街浪徒 提交于 2019-12-22 17:49:03

问题


How to implement: I have UIBarButtonItem with a search icon, after I click on it, I want to show the search bar in navigation bar and on click cancel button in search bar, I want to show navigation bar without search and with buttons and title like in IOS 7 calendar app.


回答1:


Setup an action for your search button to present a UISearchController. See the Search > Present Over Navigation Bar demo in Apple's UICatalog sample code:

- (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];
}


来源:https://stackoverflow.com/questions/26557652/how-to-show-hide-a-search-bar-inside-a-navigation-bar-ios-8-as-in-apples-cale

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