Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

searchBar textDidChange

In my tableViewController with a searchBar I am using the following method:

-(void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText 
{
   ...my code
}

and it works fine when I type text directly into the searchBar.

The problem I have now is that I want to invoke this method programatically - meaning that I want to fill in the search bar from my code which I know how to do (actually I am selecting a recently searched word in my language dictionary application) and call something like:

 [SearchBar textDidChange: recentlySearchedWord]

but this simply does not work from anywhere in my code.

Please help me if you have some idea how to solve this.

Thanks,

Tim

like image 543
user1454623 Avatar asked Jul 28 '12 15:07

user1454623


2 Answers

If you implement UISearchBar's delegate method - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText in your view controller (or any class) and you want to call that method from within the same class, which is what you want to do I'm assuming, you'd have to call

[self searchBar:SearchBar textDidChange:recentlySearchedWord];

with SearchBar being the instance of the UISearchBar you are referencing.

like image 157
Sascha Avatar answered Oct 19 '22 22:10

Sascha


textDidChange is not a class method. So instead of calling:

[SearchBar textDidChange: recentlySearchedWord];

call

[self searchBar:mySearchBar textDidChange: recentlySearchedWord];

Or if textDidChange is in a different class, use the class instance insted of self.

like image 1
Owen Hartnett Avatar answered Oct 19 '22 20:10

Owen Hartnett