简体   繁体   中英

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;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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