2015-07-28 51 views
1

我將搜索欄添加到tableview。當我開始搜索時,搜索結果的第一行正在隱藏。我嘗試了以下方法來糾正它,但它不起作用。第一行tableview被搜索欄隱藏iOS

self.categoryTableView.contentOffset = CGPointMake(0.0, 44.0); 

在此先感謝。

+1

如果它對應於單元格的高度,則應首先檢查行高。 – Omar

+0

行高爲60 – VJVJ

+0

請確保您爲 - tableView:heightForRowAtIndexPath: 返回此值,並在 - tableView:heightForHeaderInSection處爲標題指定適當的高度:如果搜索欄是標題的一部分。 – Omar

回答

0

增加了以下它工作正常。

-(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; 
    } 
} 
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; 
+0

搜索欄不會添加到tableview – VJVJ