1

I need my searchBar to display search results when searchbar's textfield becomes active. I use

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar 

call, but have no object to show UISearchResultsTableView at once. It shows only when entering fist letter in search textfield.

Wain
  • 118,658
  • 15
  • 128
  • 151
Aleks
  • 121
  • 1
  • 7

2 Answers2

3

Logic of filtering out the search result should be added in

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText

delegate method.

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar 

can be used to refresh the array objects when you start editing the search bar.

Keerthi Shekar
  • 176
  • 1
  • 8
  • That's is not what is particularly needed. I need to display all available search results below when text field is empty just when it gets focus. What method should I call? – Aleks Dec 21 '15 at 13:43
  • If the searchBar Text is nil or empty, the array assigned to the tableview should have all the results. If it is empty, that is when you get no results. – Keerthi Shekar Dec 21 '15 at 14:09
  • Array is not empty, it has all results, but it doesn't display it on the screen of iPhone. – Aleks Dec 21 '15 at 14:34
  • It displays results only when I put first letter in the search textbox. – Aleks Dec 21 '15 at 14:35
  • Does the table view show all the results before the searchBar is selected or before the focus is set on the searchBar – Keerthi Shekar Dec 21 '15 at 15:24
  • No, table view just loads the content but doesn't show it. – Aleks Dec 21 '15 at 15:38
  • Then your datasource for the tableview must be missing. Check that or Check if the cell gets the proper data from the Array of search results – Keerthi Shekar Dec 21 '15 at 16:54
  • I've checked: xcode creates tableview (all methods like cellForRow and row- and header- count are called), but doesn't display it. – Aleks Dec 22 '15 at 04:49
  • Try populating the tableview even before the searchBar is active – Keerthi Shekar Dec 22 '15 at 06:13
0

Use this method:

- (void)textFieldDidBeginEditing:(UITextField *)textField;

It will be executed on touch the textfield .

marchiore
  • 582
  • 2
  • 6
  • 21