Search button in search bar does not work in ios 7 sometimes

The Cancel button in the search bar does not work in iOS 7 when the search bar is initially hidden.

I follow this guide to create a search bar in tableview:

textbook on radiation therapy

There is an example project in this tutorial, it is better to use this project than my explanation :)

On iOS 5 and 6 it works fine. I reviewed all the delegates.

There are two possibilities. The first is to press the button when the panel is hidden, the second is to press the button when the panel is displayed (moving the table down using gestures that you can see in the search bar)

If the search bar is hidden, the cancel cancel button does not work, it does not call the calcel delegate method:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar 

Sorry, I can’t explain it better.

thanks

+6
ios ios7 tableview uisearchbar
source share
5 answers

I googled all over the internet and could not find a solution. so I changed the behavior of the UItableview.

instead of [searchBar becomeFirstResponder]; I am browsing a table.

 - (IBAction)goToSearch:(id)sender { scroll down to show the table. // CGRect newBounds = self.tableView.bounds; // newBounds.origin.y =0; // // self.tableView.bounds = newBounds; //[searchBar becomeFirstResponder]; CGPoint contentOffset=self.tableView.contentOffset; contentOffset.y=0; [self.tableView setContentOffset:contentOffset animated:YES]; } 

in my ViewDidload:

 // CGRect newBounds = self.tableView.bounds; // newBounds.origin.y = newBounds.origin.y + searchBar.bounds.size.height; // self.tableView.bounds = newBounds; CGPoint contentOffset=self.tableView.contentOffset; contentOffset.y=self.tableView.bounds.origin.y + searchBar.bounds.size.height; self.tableView.contentOffset=contentOffset; 

If for some reason it is found, in iOS 7, change the borders of the table table so that the search bar disappears. Hope this helps.

+3
source share

Put this code in your project, it will work, I tested it, and it works correctly

  -(void)searchBarSearchButtonClicked:(UISearchBar *)searchbar { [searchbar resignFirstResponder]; for (UIView *possibleButton in searchbar.subviews) { if ([possibleButton isKindOfClass:[UIButton class]]) { UIButton *cancelButton = (UIButton*)possibleButton; cancelButton.enabled = YES; break; } } } 
+1
source share

This code works for me on iOS7:

 - (IBAction)goToSearch:(id)sender { [self.tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO]; [candySearchBar becomeFirstResponder]; } 
+1
source share

This problem seems to come from the new behavior of the translucent property in the navigation bar.

Since the navigation bars of iOS 7 are translucent by default. And it looks like it overlaps the search bar when you show it after clicking a button.

Try installing in the controller:

 float osVersion = [[[UIDevice currentDevice] systemVersion] floatValue]; if (osVersion >= 7.0) { self.navigationController.navigationBar.translucent = NO; } 

This should quickly solve the problem.

But I think that for a better fix, you should see the iOS 7 migration guide , where they explain how to handle translucent navigation bars.

Hope this helps.

0
source share

I assume you set _searchBar.delegate = self and _searchBar.delegate = self UISearchBarDelegate into your class.

Here's how you do it:

 - (void) searchBarTextDidBeginEditing:(UISearchBar *)searchBar{ [searchBar setShowsCancelButton:YES animated:YES]; } - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{ // called when cancel button pressed searchBar.text = nil; //hide cancel button [_searchBar setShowsCancelButton:NO animated:YES]; [searchBar resignFirstResponder]; } 
0
source share

All Articles