如何在表View Controller中修复搜索栏的位置

问题描述 投票:0回答:1

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

swift4 uisearchbar
1个回答
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
}
© www.soinside.com 2019 - 2024. All rights reserved.