How to show / hide the search bar inside the navigation bar (iOS 7), as in the Apple Calendar app?

I want to use the search bar button in the navigation bar to show the search bar in the same way as Apple in the Calendar app. The cancel button will cancel the search bar and return the navigation bar to its previous state, buttons on the panel, title bar, etc.

Using the iOS 7 property:

self.searchDisplayController.displaysSearchBarInNavigationBar = YES;

puts the search bar in the navigation bar just fine. My problem is that it appears conditionally when a bar button is pressed. I tried to run this line from my button, but did not leave. I tried setActive: Animated: on searchDisplayController

self.searchDisplayController.active = YES;

but no luck. Any ideas or help would be appreciated.

+4
2

, , Apple , , UITableView . , , UIViewController UITableView UISearchBar, tableView .

, UISearchBar , , .

. :

WillAppear:

- (void)viewWillAppear:(BOOL)animated {

// scroll search bar out of sight
CGRect newBounds = self.tableView.bounds;
if (self.tableView.bounds.origin.y < 44) {
    newBounds.origin.y = newBounds.origin.y + self.searchBar.bounds.size.height;
    self.tableView.bounds = newBounds;
}
// new for iOS 7
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0] atScrollPosition:0 animated:YES];}

, , , , :

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
    [self viewWillAppear:YES];
}

searchBar :

- (IBAction)displaySearchBar:(id)sender {
    // makes the search bar visible
    [self.searchBar becomeFirstResponder];
}
+3

iOS 8 UISearchController, , Calendar.app. Apple UICatalog .

+2

Source: https://habr.com/ru/post/1526740/


All Articles