skip to Main Content

When scroll the tableview table section header should not scroll from his place only table cells should scrollable.

I selected UITableView style plain and disabled Bounce on scroll. But, Still it is little bit scrolling with table view cells when scrolling.

2

Answers


  1. As per understanding, i think you can use a UITableView with a plain style and set the table view’s sectionHeaderTopPadding property to 0. Additionally, you can disable the bounce effect to prevent any unintentional scrolling of the section header. Here’s how you can do it:

    import UIKit
    
    class YourTableViewController: UITableViewController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            // Disable the bounce effect
            tableView.bounces = false
    
            // Set the section header top padding to 0
            if #available(iOS 15.0, *) {
                tableView.sectionHeaderTopPadding = 0
            }
        }
    
        // Implement the UITableViewDataSource methods as needed
    }
    

    By setting tableView.bounces to false, you prevent the table view from bouncing and thus prevent any scroll of the section header. Setting tableView.sectionHeaderTopPadding to 0 ensures that the section header remains fixed at the top without any additional padding.

    This should result in a table view where only the table cells scroll while the section header remains fixed in place. Please note that the sectionHeaderTopPadding property is available starting from iOS 15, so make sure your deployment target includes this iOS version or use it accordingly if you are targeting older versions.

    Login or Signup to reply.
  2. Use a UICollectionView with a UICollectionViewFlowLayout, and the sectionHeadersPinToVisibleBounds property will do the trick

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search