我正在尝试修复tableViewController中搜索栏的位置,我知道如何在导航栏中执行此操作,但是如果没有导航栏,我找不到任何关于如何操作的文档。
1.创建单元格xib并在单元格中设置搜索栏(例如:您的单元名称为SearchBarCell)
2.现在将SearchBarCell设置为“viewForHeaderInSection”
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let cell = tableView.dequeueReusableCell(withIdentifier: "SearchBarCell") as! SearchBarCell
return cell
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 50
}