Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISearchBar's Cancel and Clear Buttons Not Working in iOS 7

I have an xCode project that contains a tableview with a “Search Bar and Search Display Controller” to allow the user to refine the list of displayed items. In general, the guidance provided in http://www.raywenderlich.com/16873/how-to-add-search-into-a-table-view was followed. I recently downloaded the latest xCode (Version 5.0 (5A1413)) with iOS 7 support and have been testing the app in question on different targets.

When running this app on an iOS 6 target (emulator or real device), it works as expected meaning that pressing the cancel button removes the search bar and pressing the clear button (little gray x) clears all of the search criteria already typed in by the user. But when the project is run on an iOS 7 target both the clear and cancel button do not work.

The searchBarCancelButtonClicked method is implemented in this project, and I have verified that it is not called when the target 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 setup to be the UISearchDisplayDelegate and UISearchBarDelegate. And it appears that this is still working as searchBar:textDidChange: is called on either a iOS 6 or 7 target.

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

I cannot see any other posts related to this or any iOS 7 change material (like https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TransitionGuide/Bars.html#//apple_ref/doc/uid/TP40013174-CH8-SW1) that mentions any recoding that needs to be done to support iOS7.

Any thoughts on this? Thanks

like image 853
Mike Avatar asked Oct 03 '13 13:10

Mike


1 Answers

I have the same problem, I tried with the following code. Please try this one.

-(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];
}
like image 141
Prabakaran Avatar answered Sep 19 '22 18:09

Prabakaran