0
votes

Now i am creating dictionary application in iOS. In my apps, I used textDidChange Event of UISearchBar with UISearchDisplayController for Auto Complete searching.

So when i type a word in SearchBar,it's automatically search in database. However i have a function in Preferences to turn off AutoComplete searching. After i turn off AutoComplete function in Preferences, It's still auto complete searching with TextDidChange Event.

I don't want TextDidChange event this time.I want to search after i enter complete word in search bar and then click Search button from Keyboard.

So how can i turn off TextDidChange event from UISearchBar? Please let me know if you ok.

Best Regards,

3

3 Answers

2
votes

In your situtation you don't want to suppress the textDidChange event. Instead you want your UISearchDisplayDelegate's shouldReloadTableForSearchString: method to return NO unless the Search button has been clicked.

You could create a boolean ivar to keep track of this. Set the ivar to NO when textDidChange is called, and set it to YES when searchBarSearchButtonClicked: is called. Then in your shouldReloadTableForSearchString: you can do the test.

EDIT: Clarified by expanding code example. (In this example I am assuming you have set up a ivar named isSearchButtonClicked).

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
    isSearchButtonClicked = NO;
}

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    isSearchButtonClicked = YES;
}

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    // returns YES if search button was clicked, otherwise return NO
    return isSearchButtonClicked;
}
1
votes

you can always create a bool variable and check if auto complete is on or not... based upon that you can search or not.

1
votes
     - (void)filterContentForSearchText:(NSString*)searchText 
                         scope:(NSString*)scope
       {
            //create a bool variable and check is Auto Complete searching is Yes or No

            if YES then pass  searchText 

            if no then Don't pass any thing unit user press the search button 

            after he press search button pass  searchText 
       }