hans
hans

Reputation: 117

iOS show a popover with tableview from search bar in navigation bar

I have a search bar in a navigation bar, and want it to behave as follows:

1) When the user starts typing in the search bar, a popover appears and shows the list of products in a table view in the popover as per the string entered in the search bar.

2) This data should be refreshed with every new letter entered.

3) Call a method when an item in the table view is selected

How can I accomplish this?

Upvotes: 1

Views: 2038

Answers (2)

hans
hans

Reputation: 117

Thanks for your help, janusfidel.

I found a good source code example that describes what I need: ToolbarSearch

Upvotes: 1

janusfidel
janusfidel

Reputation: 8116

using a UISearchBar, you can accomplish this, it has delegate method that listens to text changes, you can use it like the code below

- (void)searchBar:(UISearchBar *)theSearchBar textDidChange:(NSString *)searchText{
    if([searchText length] > 0) {
      [searchResultArray removeAllObjects];
      searchResultArray = [self searchTableView:textFromSearchbar];
      [popOverView presentData:searchResultArray];
   }
}



-(NSMutableArray*)searchTableView:(NSString*)string{
     NSMutableArray* result;
     //do the searching now
     return result;
 }

Upvotes: 0

Related Questions