Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Uitableview UISearchController';的搜索栏与第一个tableview单元格重叠_Uitableview_Swift_Ios8_Uisearchcontroller - Fatal编程技术网

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

Uitableview UISearchController';的搜索栏与第一个tableview单元格重叠,uitableview,swift,ios8,uisearchcontroller,Uitableview,Swift,Ios8,Uisearchcontroller,我正在使用UISearchController,UISearchBar也有一个范围栏。搜索栏作为子视图添加到UItableView上方的UIView中。我这样做是因为我希望搜索栏在滚动tableview时始终可见 问题是范围栏与第一个tableview单元格重叠 故事板 与tableview单元格重叠的范围栏 如何防止这种重叠?我无法在导航栏中显示搜索栏,因为放置在导航栏中的范围栏不会显示。在UIViewController上添加搜索栏和表视图,如下图所示。不要将搜索栏与表视图重叠。我正在我

我正在使用
UISearchController
UISearchBar
也有一个范围栏。搜索栏作为子视图添加到
UItableView
上方的
UIView
中。我这样做是因为我希望搜索栏在滚动tableview时始终可见

问题是范围栏与第一个tableview单元格重叠

故事板

与tableview单元格重叠的范围栏


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

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

这对我很有效:

在tableview标题中具有搜索显示控制器和搜索栏。在TableViewController中添加“头部高度”部分

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 44; //I used the 44, the height of SearchBar
}
在您的情况下,还需要添加范围栏高度。 现在它将始终保持一个基准高度

这对我很有用:

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

您可以尝试设置
tableView.contentInset=UIEdgeInsetsMake(64,0,0)
,这会将tableView的内容向下推64个点…您应该将其设置为scopebar的大小…@chuthan20我应该在哪里尝试设置这个,是否有在UISearchController激活时触发的方法?您可以将视图控制器设置为UISearchController的代理,
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UISearchControllerDelegate_Ref/index.html
我可以按照评论中的建议,使用
UIEdgeInsetsMake
使其正常工作。我的设置与您在图像中所做的完全相同,但这对我不起作用!对于包含节的表,当搜索控制器未激活时,我将更改为“return 20;//no scope”。因为当值为0时,将隐藏节标题。