增加TableView标头的大小

时间:2012-03-27 16:52:23

标签: iphone ios uitableview uisearchbar

使用故事板,我做了UITableViewController

enter image description here

好的,当我开始搜索时,在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;
}

但是表的第一个单元格隐藏在范围栏后面。我想我需要增加表头,但我是怎么做到的?或者有其他方法来解决它?

2 个答案:

答案 0 :(得分:1)

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;

答案 1 :(得分:1)

回答我自己的问题,再看一点,我找到了一个似乎最正确的解决方案,即使用UISearchDisplayController。这是我遵循的教程:https://developer.apple.com/library/ios/#samplecode/TableSearch/Introduction/Intro.html

使用这种方式,他隐藏了导航栏并显示了范围,无需额外的代码,也没有隐藏第一个单元格的问题。

相关问题