簡體   English   中英

增加TableView標頭的大小

[英]Increase size of TableView header

使用storyboard,我創建了這個UITableViewController

在此輸入圖像描述

好的,當我開始搜索時,在searchBarShouldBeginEditing:我將隱藏導航欄並顯示范圍欄:

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
    [self.mySearchBar setShowsScopeBar:YES];
    [self.mySearchBar sizeToFit];
    [self.mySearchBar setShowsCancelButton:YES animated:YES];
    [self.navigationController setNavigationBarHidden:YES animated:YES];

    return YES;
}

但是表的第一個單元格隱藏在范圍欄后面。 我想我需要增加表頭,但我是怎么做到的? 或者有其他方法來解決它?

UITableViewDelegate有一個執行此操作的方法:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    //return height as a float here
}

在您的委托中以適當的高度實現它。

或者,如果條形圖隱藏單元格的頂部,您可能需要通過更改其框架來向下移動屏幕上的表格視圖,如下所示:

CGRect newFrame = tableView.frame;
newFrame.origin.y += 45; //or whatever number of pixels you want to move it down by
tableView.frame = newFrame;

回答我自己的問題,再看一點,我找到了一個看似最正確的解決方案,即使用UISearchDisplayController 這是我遵循的教程: https//developer.apple.com/library/ios/#samplecode/TableSearch/Introduction/Intro.html

使用這種方式,他隱藏了導航欄並顯示了范圍,無需額外的代碼,也沒有隱藏第一個單元格的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM