1

我有一個帶有標準UITableView的UIViewController和添加了Search委託的搜索欄。該視圖在導航欄中有一個分段控件,當用戶更改分段控件時,我想隱藏searchBar。隱藏UITableView searchBar留下一個空格

我使用的代碼是:

- (void)segChange { 
    if ([segmentedControl selectedSegmentIndex] == 0) { 
     [[[self searchDisplayController] searchBar] setHidden:YES]; 

     // This does not work: 
     [[[self searchDisplayController] searchResultsTableView] setContentOffset:CGPointZero animated:NO]; 

    } 
    else { 
     [[[self searchDisplayController] searchBar] setHidden:NO]; 
    } 


} 

的代碼隱藏搜索欄很好,但它也使表格視圖頂部討厭的白色空間....如何得到任何想法擺脫它???

感謝

回答

6

此代碼解決了這個問題:

- (void)segChange { 
    if ([segmentedControl selectedSegmentIndex] == 0) { 
     [self.myTableView setTableHeaderView:nil]; 
    } 
    else { 
     [self.myTableView setTableHeaderView:[[self searchDisplayController] searchBar]]; 
    } 
} 
+0

正是我在找的!謝謝......像魅力一樣工作! – 2015-10-22 14:38:18

1

而不是隱藏分段控制嘗試它的框架設置爲CGRectZero

+0

謝謝您的回答。分段控制器在導航欄中,我試圖隱藏搜索欄。我嘗試將searchBar設置爲CGRectZero,但是這也不起作用。 – KSoza 2010-11-11 09:40:56