繁体   English   中英

搜索栏iOS隐藏了tableview的第一行

[英]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;
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM