Fix: Nested UITableView Scroll Conflicts with Parent UIScrollView in UIKit

Written by

in

Quick answer: Disable the UITableView’s scrolling initially and use UIScrollViewDelegate to toggle scrolling between the parent UIScrollView and child UITableView based on content offset. When the parent scroll view reaches its bottom, enable table view scrolling; when the table view reaches its top, re-enable the parent scroll view.

Why this happens

When you embed a UITableView inside a UIScrollView — especially within a UIPageViewController page — both scroll views compete for the same touch events. By default, iOS delivers touches to the deepest view in the hierarchy that can handle them, so the table view intercepts scroll gestures before the parent scroll view ever sees them.

There is no built-in coordination between nested scroll views. The system doesn’t know that you want the outer scroll view to consume gestures until it hits a boundary, then hand off to the inner table view. Without explicit logic, the table view always scrolls first, leaving the parent scroll view stuck at its current offset.

This problem appears most often in “parallax header” or “sticky header” layouts where a large scrollable content area sits above a list. The expected behavior is: scroll the header/content area first; only when it reaches its bottom should the list begin to scroll. Reversing that order at the top edge completes the natural feel.

How to fix it

1. Delegate-based scroll coordination (recommended)

The most reliable approach is to make your view controller the UIScrollViewDelegate for both scroll views and toggle isScrollEnabled based on content offsets. This gives you precise control over the hand-off points.

Setup

import UIKit

class CoordinatedScrollViewController: UIViewController, UIScrollViewDelegate {
    @IBOutlet private weak var outerScrollView: UIScrollView!
    @IBOutlet private weak var tableView: UITableView!

    // Height of the outer scroll view's content (header + any fixed content)
    private let outerContentHeight: CGFloat = 1200
    private let screenHeight = UIScreen.main.bounds.height

    override func viewDidLoad() {
        super.viewDidLoad()
        configureScrollViews()
    }

    private func configureScrollViews() {
        outerScrollView.contentSize = CGSize(width: view.bounds.width, height: outerContentHeight)
        outerScrollView.delegate = self
        outerScrollView.bounces = false

        tableView.delegate = self
        tableView.dataSource = self
        tableView.bounces = false
        tableView.isScrollEnabled = false // Start disabled
    }
}

// MARK: - UIScrollViewDelegate

extension CoordinatedScrollViewController {
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        let yOffset = scrollView.contentOffset.y

        if scrollView == outerScrollView {
            // Outer scroll view reached its bottom → enable table view
            let atBottom = yOffset >= outerContentHeight - screenHeight
            tableView.isScrollEnabled = atBottom

            // If we just enabled the table view, lock the outer scroll view
            if atBottom {
                outerScrollView.isScrollEnabled = false
            }
        } else if scrollView == tableView {
            // Table view reached its top → re-enable outer scroll view
            let atTop = yOffset <= 0
            outerScrollView.isScrollEnabled = atTop

            if atTop {
                tableView.isScrollEnabled = false
            }
        }
    }
}

Key points

  • Disable bounces on both scroll views to prevent rubber-banding from confusing the offset checks.
  • The threshold outerContentHeight - screenHeight is the exact offset where the outer scroll view’s bottom aligns with the screen bottom.
  • Toggling isScrollEnabled instantly transfers gesture recognition to the other scroll view without requiring a touch release.

2. Constraint-based table height with simplified logic

If your table view should always fill the visible screen height (common for full-screen lists), you can size it with Auto Layout and simplify the delegate logic. This version comes from a community refinement of the first answer.

class SimplifiedScrollViewController: UIViewController, UIScrollViewDelegate, UITableViewDataSource, UITableViewDelegate {
    @IBOutlet private weak var outerScrollView: UIScrollView!
    @IBOutlet private weak var tableView: UITableView!
    @IBOutlet private weak var tableHeightConstraint: NSLayoutConstraint!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Make table view exactly the screen height (minus nav bar if opaque)
        let navBarHeight = navigationController?.navigationBar.frame.height ?? 0
        let statusBarHeight = view.window?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0
        tableHeightConstraint.constant = view.bounds.height - navBarHeight - statusBarHeight

        outerScrollView.bounces = false
        outerScrollView.delegate = self

        tableView.bounces = true // Allow bounce on the list
        tableView.isScrollEnabled = false
        tableView.dataSource = self
        tableView.delegate = self
    }

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        if scrollView == outerScrollView {
            // Enable table view once outer scroll view passes a threshold (e.g., 200 pt)
            tableView.isScrollEnabled = outerScrollView.contentOffset.y >= 200
        } else if scrollView == tableView {
            // Keep table view enabled only while it has scrolled content
            tableView.isScrollEnabled = tableView.contentOffset.y > 0
        }
    }

    // MARK: - UITableViewDataSource
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 20 }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
        cell.textLabel?.text = "Row \(indexPath.row + 1)"
        return cell
    }
}

Why this works

  • The table view’s height constraint guarantees it never exceeds the viewport, so its content offset directly reflects user scrolling.
  • The hard-coded 200 threshold replaces the dynamic calculation; adjust it to match your header height.
  • Keeping bounces = true on the table view preserves the standard iOS list feel once scrolling starts.

3. Integrating with UIPageViewController

When each page of a UIPageViewController contains its own table view, the coordination must happen per page. The page view controller itself manages a UIScrollView for page transitions, so you now have three scroll views in the hierarchy.

Strategy

  1. Make each page’s view controller adopt the delegate logic above.
  2. Disable the page view controller’s scroll view bouncing (pageViewController.scrollView?.bounces = false) if you want vertical scrolling to take priority over horizontal page swipes.
  3. Forward the scrollViewDidScroll calls from the page view controller’s scroll view to the current page’s coordinator if you need cross-axis coordination.
class PageContentViewController: UIViewController, UIScrollViewDelegate {
    @IBOutlet private weak var tableView: UITableView!
    weak var outerScrollView: UIScrollView? // Injected by parent

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.delegate = self
        tableView.dataSource = self
        tableView.isScrollEnabled = false
        tableView.bounces = false
    }

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        guard let outer = outerScrollView else { return }

        if scrollView == outer {
            let threshold = outer.contentSize.height - outer.bounds.height
            tableView.isScrollEnabled = outer.contentOffset.y >= threshold
            if tableView.isScrollEnabled { outer.isScrollEnabled = false }
        } else if scrollView == tableView {
            outer.isScrollEnabled = tableView.contentOffset.y <= 0
            if outer.isScrollEnabled { tableView.isScrollEnabled = false }
        }
    }
}

The parent view controller (or a dedicated coordinator) sets outerScrollView on each page when pageViewController(_:viewControllerBefore:) / pageViewController(_:viewControllerAfter:) are called.

How to prevent it

  • Design the scroll hierarchy early — decide whether a single UICollectionView with compositional layout can replace nested scroll views.
  • Use UICollectionView compositional layout for mixed header + list layouts; it handles coordinated scrolling natively.
  • Disable bounces on all but the innermost scroll view to avoid conflicting rubber-band animations.
  • Test on device — simulator scrolling inertia differs from real hardware and can mask hand-off bugs.
  • Avoid scrollEnabled toggles during active deceleration — the delegate method fires rapidly; the boolean checks are cheap but guard against rapid flip-flopping with a small hysteresis if needed.

FAQ

Can I use UIScrollView‘s panGestureRecognizer.require(toFail:) instead?

No. Gesture recognizer failure requirements work for discrete gestures (tap vs. double-tap), not for continuous panning where both recognizers must track the same finger simultaneously. Toggling isScrollEnabled is the supported way to transfer control mid-gesture.

Why does the table view sometimes “stick” after the hand-off?

If bounces is enabled on the outer scroll view, its content offset can overshoot the threshold during deceleration, causing isScrollEnabled to toggle rapidly. Disable bounces on the outer scroll view (and optionally the table view) to keep the hand-off clean.

Does this work with UICollectionView instead of UITableView?

Yes. UICollectionView inherits from UIScrollView, so the exact same delegate logic applies. Replace tableView with collectionView and ensure the collection view’s layout doesn’t introduce its own nested scrolling (e.g., orthogonal scrolling sections).

Sources & credits

Parts of this guide are adapted from content licensed under CC BY-SA 3.0; this article is shared under the same license.