[英]First row of tableview is hidden by search bar iOS
I added the search bar to the tableview. 我在表视图中添加了搜索栏。 When i start search first row of search result is getting hidden. 当我开始搜索时,搜索结果的第一行被隐藏。 I tried the following way to rectify it but it doesn't work. 我尝试了以下方法来纠正它,但是它不起作用。
self.categoryTableView.contentOffset = CGPointMake(0.0, 44.0);
Thanks in advance. 提前致谢。
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0,0,self.categoryTableView.frame.size.width, 60)] ;
[headerView setBackgroundColor:[UIColor clearColor]];
UISearchBar *txtSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(10, 10,self.categoryTableView.frame.size.width - 20 , 40)];
[headerView addSubview:txtSearchBar];
self.categoryTableView.tableHeaderView = headerView;
Added the following it worked fine. 添加以下内容,效果很好。
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *view;
if(isFiltered)
{
view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.categoryTableView.frame.size.width, 45)];
}
else
{
view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
}
return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if(isFiltered)
{
return 45;
}
else
{
return 0;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.