Is there a simple way to disable scrolling of an NSTableView.
It seems there isn\'t any property on
[myTableView enclosingScrollView]
or [[myTable
Here's the best solution in my opinion:
import Cocoa
@IBDesignable
@objc(BCLDisablableScrollView)
public class DisablableScrollView: NSScrollView {
@IBInspectable
@objc(enabled)
public var isEnabled: Bool = true
public override func scrollWheel(with event: NSEvent) {
if isEnabled {
super.scrollWheel(with: event)
}
else {
nextResponder?.scrollWheel(with: event)
}
}
}
Simply replace any NSScrollView
with DisablableScrollView
(or BCLDisablableScrollView
if you still use ObjC) and you're done. Simply set isEnabled
in code or in IB and it will work as expected.
The main advantage that this has is for nested scroll views; disabling children without sending the event to the next responder will also effectively disable parents while the cursor is over the disabled child.
Here are all advantages of this approach listed out:
NSScrollView