UISearchBar Undo and clear buttons that do not work in iOS 7

I have an xCode project that contains a tabular view with a “search bar and search display” so that the user can refine the list of displayed items. In general, the guidelines given at http://www.raywenderlich.com/16873/how-to-add-search-into-a-table-view have been followed. I recently downloaded the latest version of xCode (version 5.0 (5A1413)) with iOS 7 support and tested the corresponding application for different purposes.

When you run this application on an iOS 6 target (emulator or real device), it works as expected that pressing the cancel button removes the search bar, and pressing the clear button (a little gray x) clears all the search criteria already entered by the user. But when the project starts on iOS 7, the clear and cancel button do not work.

The searchBarCancelButtonClicked method is implemented in this project, and I confirmed that it is not called when the target application is running iOS 7.

- (void)searchBarCancelButtonClicked:(UISearchBar *)SearchBar { NSLog(@"searchBarCancelButtonClicked called"); self.searchBar.text = nil; … // Hide Search bar when cancelled [self hideSeachBar]; [self.searchBar resignFirstResponder]; … } 

My table view controller is configured as UISearchDisplayDelegate and UISearchBarDelegate. And it looks like this still works as searchBar: textDidChange: is called for either iOS 6 or 7 goals.

 @interface ItemViewController () <UISearchDisplayDelegate, UISearchBarDelegate> … @end 

I do not see other posts related to this or any material for changing iOS 7 (e.g. https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TransitionGuide/Bars.html#//apple_ref/doc / uid / TP40013174-CH8-SW1 ), which mentions any transcoding that must be done to support iOS7.

Any thoughts on this? Thanks

+7
ios objective-c ios7 uisearchbar
source share
6 answers

I have the same problem, I tried with the following code. Try it.

 -(void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller { controller.active = YES; [self.view addSubview:controller.searchBar]; [self.view bringSubviewToFront:controller.searchBar]; } - (void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView { tableView.frame = self.archiveListTblView.frame; } - (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller { controller.active=NO; [self.view addSubview:controller.searchBar]; } 
+3
source share
Button

Cancel and the Reset button will not work if you click the "Navigate Search" button. If you click on the search bar in the star, it works fine => This means that if the search bar does not appear on the screen before searching for a search, these buttons also appear to be disabled.

So, I found a solution, but it is not quite perfect. Before you make the search bar become the first answer, you need to scroll up the table. Try this code.

 -(IBAction)goToSearch:(id)sender { // Make search bar visible on screen before make it response [_tableView setContentOffset:CGPointMake(0, 0) animated:NO]; // Make search bar active [candySearchBar becomeFirstResponder]; } 

The only problem arises if you do this, it will look like a table, which means that when you cancel the search, you lost the current cell index earlier.

+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. If you go to the top of the ListView and use the search bar, it should work correctly.

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.

+1
source share

I also had this problem. Oddly, the other methods of the UISearchBarDelegate delegate are called. Workaround may be:

 - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{ if ([searchText length] == 0) { NSLog("No Text"); } } 

It worked for me

+1
source share

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.

0
source share

In my case, I moved the search bar to the top of the screen, and an invisible view appeared that overlaps the search bar.

Thus, the cancel button was not actually affected.

So, I cited a rising edge when the [searchBarTextDidBeginEditing] method was called, as shown below.

 -(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{ lc_SearchBarYPos.constant = 20.0f; //this is code to reposition the searchbar [self.view bringSubviewToFront:searchBar]; } 

Hope this helps.

0
source share

All Articles