簡體   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