I'm facing a really strange problem, where I can not scroll to the bottom in UISearchResultsTableViewaltough the frame of the tableView and the contentSize is correct.
It only happens if I click on "Cancel" and enter a new search string. If I clear this string and enter again, everything works fine. If I click "Cancel" again and enter a new string, I can't scroll to the bottom. It seems to me like the second search works, but I'm having a problem with the first search or after clicking the "Cancel" button in UISearchBar.
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self searchForText:searchString];
return YES;
}
- (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide) name:UIKeyboardWillHideNotification object:nil];
}
- (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView
{
tableView.rowHeight = 70;
}
- (void)searchDisplayController:(UISearchDisplayController *)controller didHideSearchResultsTableView:(UITableView *)tableView
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardWillHide
{
UITableView *tableView = [[self searchDisplayController] searchResultsTableView];
[tableView setContentInset:UIEdgeInsetsZero];
[tableView setScrollIndicatorInsets:UIEdgeInsetsZero];
}
I've also subclassed my UISearchDisplayController
- (void)setActive:(BOOL)visible animated:(BOOL)animated
{
if(self.active == visible) return;
[self.searchContentsController.navigationController setNavigationBarHidden:YES animated:NO];
[super setActive:visible animated:animated];
[self.searchContentsController.navigationController setNavigationBarHidden:NO animated:NO];
if (visible) {
[self.searchBar becomeFirstResponder];
} else {
[self.searchBar resignFirstResponder];
}
}
Additionally I'm also using a custom cell, which is registered like this
[self.searchDisplayController.searchResultsTableView
registerNib:[UINib nibWithNibName:@"..." bundle:nil] forCellReuseIdentifier:@"..."];
I solve the problem, I think you need to check you tableview contentInset property in tableview "cellForRowAtIndexPath" method. It's not UIEdgeInsetsZero. I solved it by set tableview content Inset to UIEdgeInsetsZero in "cellForRowAtIndexPath" method. It's a little wired, but it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With