Reputation: 50752
I have a tableview in my app...The contents of this list view are displayed based on ext API dynamic search...
e.g. If I type "G" in searchbar it will display GA, GB, GC1, GC2, GC3,..
if I now change to GC, it will only display GC1, GC2, GC3..
I am storing the items in an array..
My question is how do I ensure that what the user is typing and seeing as search results are synchronized..I mean if he clicks on GC1 in list view, he should see GC1's detail and not other's..
Also when is cellForRowAtIndexPath called so that I can update the array each time user types in searchbar?
Upvotes: 1
Views: 6698
Reputation: 11914
You should be updating your array of filtered items in the filterContentForSearchText: scope:
method. There is another method, searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
that will be called when the user types in the search bar. If you return YES from this method, then the table will be reloaded, which causes cellForRowAtIndexPath:
to be called.
Upvotes: 1
Reputation: 125007
-cellForRowAtIndexPath: is sent by the table anytime it wants a cell to display, such as when the table is redrawn, or when a new cell is needed because the user scrolled a bit.
You can force the table to update its contents by calling [table reloadData], if 'table' is a pointer to your table.
Upvotes: 4