UISearchController的搜索栏与第一个tableview单元格重叠 [英] UISearchController's search bar overlaps first tableview cell
问题描述
我正在使用 UISearchController
而 UISearchBar
也有一个范围栏。搜索栏作为子视图添加到 UIView
,它位于 UItableView
之上。我这样做了,因为即使滚动了tableview,我也希望搜索栏始终可见。
问题是scopebar与第一个tableview单元格重叠
StoryBoard
范围栏重叠于tableview单元格
如何防止这种重叠?我可以不会在导航栏中显示搜索栏,因为放置在导航栏中的范围栏不会显示。
这对我有用:
在tableview标题中使用Search Display Controller和SearchBar。在TableViewController中添加 heightForHeaderInSection
。
- (CGFloat)tableView: (UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 44; //我使用了44,SearchBar的高度
}
在你的情况下你'我还需要添加范围栏高度。
现在它将始终保持基本高度。
I am using UISearchController
and the UISearchBar
also has a scope bar. The search bar is added as a subview to a UIView
which is above the UItableView
. I have done it this way since I want the search bar to be always visible even when the tableview is scrolled.
The problem is the scopebar overlaps the first tableview cell
StoryBoard
Scope bar overlapping the tableview cell
How can I prevent this overlapping?, I can't display the searchbar in navigationbar since the scopebar when placed in navigation bar does not get displayed.
This worked for me:
Having the Search Display Controller and SearchBar in the tableview header. Add the heightForHeaderInSection
in your TableViewController.
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 44; //I used the 44, the height of SearchBar
}
In your case you'll need to also add the scope bar height. Now it will always keep a base height.
这篇关于UISearchController的搜索栏与第一个tableview单元格重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!