romansorochak / ParallaxHeader

Simple way to add parallax header to UIScrollView/UITableView written in Swift.
MIT License
1.03k stars 131 forks source link

Cannot Use Header Sections In a UITableView #11

Closed MattFlood7 closed 7 years ago

MattFlood7 commented 7 years ago

Using the parallax header with a UITableView that has header sections causes scrolling issues with the header sticking in the view until scrolling to another header section.

class UserHomeViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    var tabBar:TabBar?
    let sections = ["Drafts", "Scheduled", "Past"]

    @IBOutlet weak var eventsTableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()

        initUI()
    }

    /// Initialize any UI components
    private func initUI(){
        initTableView()
        tabBar = TabBar.init(self.view, navController: self.navigationController!, isVendor: false, selectedTab: 0)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    /// Initialize the trip table view
    fileprivate func initTableView(){

        eventsTableView.register(UINib(nibName: "TripTableViewCell", bundle: nil), forCellReuseIdentifier: "TripTableViewCell")
        eventsTableView.rowHeight = 60

        eventsTableView.parallaxHeader.view = (Bundle.main.loadNibNamed("ParallaxHeaderView", owner: self, options: nil)![0] as? UIView)!
        eventsTableView.parallaxHeader.height = 120
        eventsTableView.parallaxHeader.minimumHeight = 0
        eventsTableView.parallaxHeader.mode = .topFill
    }

    /// Set the number of entries in table view
    /// - parameter tableView: table view we are getting the size of.
    /// - parameter section: section of the table view we are getting the size of.
    /// - returns: the size of the table view.
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        var size = 0

        switch section {
        case 0:
            size = 5
        case 1:
            size = 5
        case 2:
            size = 5
        default:
            size = 0
        }

        return size
    }

    /// Set the values for the table view cells
    /// - parameter tableView: table view that the cell is being initialized for.
    /// - parameter indexPath: row in the table view that the cell will be placed.
    /// - returns: the initialized table view cell.
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCell(withIdentifier: "TripTableViewCell", for: indexPath) as! TripTableViewCell

        return cell
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        return sections.count
    }

    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 30.0
    }

    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

        let header = Bundle.main.loadNibNamed("EventsHeaderView", owner: self, options: nil)![0] as! EventsHeaderView
        header.headerLabel.text = sections[section]

        return header
    }
}
havocked commented 6 years ago

I found the same issue. The only way to fix this for now is to use grouped style for tableView.

But It would be nice to use the default style.

Any suggestions ?

furiosFast commented 6 years ago

hi, with grouped table i've the same problem. any solution?

iprabhakarpatil commented 2 years ago

Is there a fix for this issue? Facing the scrolling issue with Grouped type too.