tableview 的第一行被搜索栏隐藏 iOS
First row of tableview is hidden by search bar iOS
我在表格视图中添加了搜索栏。当我开始搜索时,搜索结果的第一行被隐藏了。我尝试了以下方法来纠正它,但它不起作用。
self.categoryTableView.contentOffset = CGPointMake(0.0, 44.0);
提前致谢。
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;
添加了以下内容,效果很好。
-(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;
}
}
我在表格视图中添加了搜索栏。当我开始搜索时,搜索结果的第一行被隐藏了。我尝试了以下方法来纠正它,但它不起作用。
self.categoryTableView.contentOffset = CGPointMake(0.0, 44.0);
提前致谢。
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;
添加了以下内容,效果很好。
-(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;
}
}