Reputation: 293
I have a UIViewController
with a UITableView
and a UISearchBar
inside. As soon as the searchbar becomes first responder, there's a small gap between the searchbar and the tableview.
There's no gap when the UISearchBar
is a subview of the UIViewController
view instead of being a subview of the UITableView
.
Obviously, one issue with that approach is that the searchbar stick to the top and doesn't scroll along with other cells, which is not desired.
Any ideas?
Edit:
Two first images correspond to the UISearchBar
being a child of the UITableView
, where the gap is occurring.
Last two images correspond to the UISearchBar
being a child of the UIViewController
view, in which case there's no gap.
Upvotes: 4
Views: 1165
Reputation: 41
I had exactly the same issue, however none of the above solutions worked. As per @plgrenier answer, the translucency of the status bar caused the issue.
One way I handled this was to use the search delegates to switch the translucency:
#pragma mark - Table Search Delegates
- (void) searchBarTextDidBeginEditing:(UISearchBar *)searchBar{
[self.navigationController.navigationBar setTranslucent:YES];
}
-(void) searchBarTextDidEndEditing:(UISearchBar *)searchBar{
[self.navigationController.navigationBar setTranslucent:NO];
}
Upvotes: 1
Reputation: 293
The gap is occurring when setting UINavigationBar
translucent property to NO
. Setting it to YES
resolve the issue. Animation is smooth again and there's no gap between UISearchBar
and UITableView
. I can't explain why, and it appears to be a bug on Apple side as it is easy to reproduce by creating a sample project.
Upvotes: 6
Reputation: 3799
I suspect it may have something to do with the fact that in a UITableView
and using a UITableViewController
, you can pull the entire table view and search bar down to reveal a space behind, a background.
When you are inserting a UISearchBar
and UITableView
into a UIView
, the "pull-down" UI is not inherited (as it is unique to UITableViewController
) so the "hint" of a "pull-down" space is not there.
To check this and hopefully solve your problem, read my answer to this previous SO question by implementing the UITableView
properties setBackgroundView
and setBackgroundColor
.
Upvotes: 0
Reputation: 2881
It's a little bit difficult without seeing the code, but perhaps try setting the uisearchbar as the uitableview's header view instead of adding it as a subview.
Upvotes: 0