Question

I am developing an iPad (iOS7) app which has following screen. On the top right side of the map I have added UITableView and a search bar and search display. But when I try to type on the search bar, it is just moving to top navigation bar as illustrated on the second screenshot. I am using storyboard to develop these interfaces. I want to stay the search bar within the tableview. Could you please help me to overcome this?

1) Initial View Initial view

2) Just after starting to type on the search bar Just after starting to type on the search bar

Thanks

Was it helpful?

Solution

This is probably because you are using UISerchDisplayController, it's an easy way to implement search functionalities, but with custom interfaces is a pain.
In my opinion is better that you manage search by yourself. Or you can try with UISearchDisplayDelegate, but on iOS7 I had a lot of main issues trying to change the searchTableView according to the app design.
In the first 2 methods I try to change the frame of the search tvc returned from the search display controller. In iOS7 this code is almost useless, they changed something internally.

#pragma mark -
#pragma mark UISearchDisplayController Delegate Methods

- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller{

    NSLog(@"Old frame %@",NSStringFromCGRect(oldTableViewFrame));
    [UIView beginAnimations:@"" context:NULL];
    [UIView setAnimationDuration:1.5];
    self.receiptsTableView.frame= self.view.bounds;
    [UIView commitAnimations];

}
- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller{
    [UIView beginAnimations:@"" context:NULL];
    [UIView setAnimationDuration:1.5];
    self.receiptsTableView.frame= CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.x+self.imageContentView.bounds.size.height, self.view.bounds.size.width,  self.view.bounds.size.height-self.imageContentView.bounds.size.height);
    [UIView commitAnimations];
}


- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    [self filterContentForSearchText:searchString scope: (NSString*)scopes[[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];

    // Return YES to cause the search result table view to be reloaded.
    return YES;
}


- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption
{
    [self filterContentForSearchText:[self.searchDisplayController.searchBar text] scope:scopes[searchOption]];

    // Return YES to cause the search result table view to be reloaded.
    return YES;
}

OTHER TIPS

the point is when you touch on UISearchBar, its default behaviour kicks in (move to the left, add cancel button ...)

so you have to override it.

this is not a perfect solution but you can either use UISearchBarDelegate and implement these methods:

searchBarShouldBeginEditing: and searchBarDidBeginEditing: (im not sure, you have to try both)

or UISearchDisplayDelegate with:

– searchDisplayControllerWillBeginSearch:
– searchDisplayControllerDidBeginSearch:

– searchDisplayControllerWillEndSearch:
– searchDisplayControllerDidEndSearch:

set its frame to your desired position when the users begin and end their search.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top