Ok, here's how I manage the search bar:
Code:
#pragma mark -
#pragma mark Content Filtering
- (void)filterContentForSearchText:(NSString*)searchText
{
/*
Update the filtered array based on the search text and scope.
*/
[self.filteredArray removeAllObjects]; // First clear the filtered array.
/*
Search the main list for products whose type matches the scope (if selected) and whose name matches searchText; add items that match to the filtered array.
*/
for (MyObject *object in objectsArray)
{
NSRange result = [object.name rangeOfString:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)];
if (result.location != NSNotFound)
{
[self.filteredArray addObject:object];
}
}
}
#pragma mark -
#pragma mark UISearchDisplayController Delegate Methods
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString];
// Return YES to cause the search result table view to be reloaded.
return YES;
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
[self.tableView reloadData];
}
Everything works just fine, expect for this problem: the tableview get resized and changes the height when the user inserts something in the search bar; when pressing "search" in the keyboard, the keyboard disappears and the tableview ends at the end of the screen. I would like it to remain in my interface. Anyone has an idea why?