0

I'm wonder how to make it right programmatically, if you know, please, share with me.

Now my code looks like this:

let tbv = SearchTableView(frame: .zero, style: .grouped)
    tbv.register(SearchTableCell.self, forCellReuseIdentifier: "searchTableCell")
    tbv.register(SearchHeaderView.self, forHeaderFooterViewReuseIdentifier: "searchHeaderView")

In SearchTableView I make all DataSource methods and also do this:

override init(frame: CGRect, style: UITableView.Style) {
    super.init(frame: frame, style: style)
    register(SearchTableCell.self, forCellReuseIdentifier: "searchTableCell")
    separatorStyle = .none
    autoresizingMask = [.flexibleWidth, .flexibleHeight]
    delegate = self
    dataSource = self
}

And for header:

func tableView(_ tableView: UITableView,
               viewForHeaderInSection section: Int) -> UIView? {
    guard let view = tableView.dequeueReusableHeaderFooterView(withIdentifier: "searchHeaderView") as? SearchHeaderView else {
        let view = SearchHeaderView(reuseIdentifier: "searchHeaderView")
        return view
    }
    return view
}
  • Yes, use `willShowCellFor` to detect when you're showing a specific cell, remove the header with a reload, then when you want to show it have a separate condition to do that. Or use a panGestureRecognizer like this. https://stackoverflow.com/questions/31857333/how-to-get-uiscrollview-vertical-direction-in-swift – xTwisteDx Oct 15 '21 at 13:30
  • Do you want the actual size to change as you scroll, or just to show/hide completely when you scroll up or down? – Rob C Oct 17 '21 at 01:05

0 Answers0