elavarasan elavarasan - 6 months ago 31
iOS Question

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.

Answer

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