title: Horizontal and vertical nested scroll views
body: <p>My view contains a horizontally scrolling Scroll View containing multiple vertically scrolling Table Views. </p>
  
  <p>See diagram:</p>
  
  <p><a href="https://i.stack.imgur.com/1pWDl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1pWDl.png" alt="enter image description here"></a></p>
  
  <p>However, the Table Views are blocking horizontal scrolling in the Scroll View when the cursor is on them.</p>
  
  <p>How can I allow the scroll to pass on to the superview?</p>
  
  <hr>
  
  <p>Code for Application</p>
  
  <pre><code>@NSApplicationMain
  class AppDelegate: NSObject, NSApplicationDelegate {
  
       @IBOutlet weak var window: NSWindow!
      var viewController: ViewController!
  
      func applicationDidFinishLaunching(aNotification: NSNotification) {
          viewController = ViewController(nibName: "ViewController", bundle: nil)  
          viewController.view.translatesAutoresizingMaskIntoConstraints = false
          window.contentView!.addSubview(viewController.view)
          //...
      }
      //...
  }
  </code></pre>
  
  <p>View Controller</p>
  
  <pre><code>class ViewController: NSViewController {
  
      @IBOutlet weak var scrollView: NSScrollView!
      //...
  
      func addListView(listPath: String) {
          let listView = ListViewController(nibName: "ListView", bundle: nil)
          listView!.listPath = listPath
  
          listView!.view.translatesAutoresizingMaskIntoConstraints = false
          scrollView.contentView.addSubview(listView!.view)
          //...
      }
      //...
  }
  </code></pre>
  
  <p>List View</p>
  
  <pre><code>class ListViewController: NSViewController {
  
      @IBOutlet weak var itemsTitleView: NSTextField!
      @IBOutlet weak var itemsTableView: MyTableView!
      //...
  }
  </code></pre>
  
  <p>TableView</p>
  
  <pre><code>class MyTableView: NSTableView {
  
      override func drawRect(dirtyRect: NSRect) {
          super.drawRect(dirtyRect)
  
          // Drawing code here.
      }
  
      var mainScrollView: NSScrollView? {
          let app = NSApplication.sharedApplication()
          let delegate = app.delegate as! AppDelegate
          return delegate.viewController.scrollView
  }
  
      override func mouseDown(theEvent: NSEvent) {
          // do nothing
      }
  
      override func scrollWheel(theEvent: NSEvent) {
          if theEvent.scrollingDeltaY == 0 {
              // It's a horizontal scroll -&gt; redirect it
              if let tableScrollView = enclosingScrollView, mainScrollView = mainScrollView {
                  mainScrollView.scrollWheel(theEvent)
              }
          } else {
              // It's a vertical scroll -&gt; behave normally
              super.scrollWheel(theEvent)
          }
      }
  
  }
  </code></pre>