如何固定tableViewController中搜索栏的位置

时间:2019-04-12 18:48:26

标签: swift4 uisearchbar

我正在尝试固定tableViewController中搜索栏的位置,我知道如何在导航栏中完成此操作,但是如果没有导航栏,我找不到任何有关如何执行此操作的文档。

1 个答案:

答案 0 :(得分:0)

1。创建单元格xib,并在单元格中设置搜索栏(例如:您的单元格名称为SearchBarCell)

2。现在将SearchBarCell设置为“ viewForHeaderInSection”

 func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let cell = tableView.dequeueReusableCell(withIdentifier: "SearchBarCell") as! SearchBarCell
    return cell
}
  1. 赋予切片高度
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 50
}
相关问题