UISearchController的搜索栏与第一个tableview单元格重叠

时间:2015-03-25 19:16:16

标签: uitableview swift ios8 uisearchcontroller

我正在使用UISearchControllerUISearchBar也有一个范围栏。搜索栏将作为子视图添加到UIView以上UItableView。我这样做了,因为即使滚动了tableview,我也希望搜索栏始终可见。

问题是作用域与第一个tableview单元重叠

故事板

enter image description here

范围栏与tableview单元格重叠

enter image description here

如何防止这种重叠?我无法在导航栏中显示搜索栏,因为放置在导航栏中的范围栏无法显示。

3 个答案:

答案 0 :(得分:6)

这对我有用:

在tableview标题中包含Search Display Controller和SearchBar。在TableViewController中添加heightForHeaderInSection

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 44; //I used the 44, the height of SearchBar
}

在您的情况下,您还需要添加范围栏高度。 现在它将始终保持基础高度。

答案 1 :(得分:2)

这对我有用:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (self.searchController.active) {
        return 44; // with scope
    } else {
        return 0; // no scope
    }
}

答案 2 :(得分:0)

在UIViewController上添加搜索栏和表格视图,如下图所示。不要将搜索栏与表格视图重叠。我在我的应用程序中使用它,它对我来说很好。

enter image description here

相关问题