问题
I've two NSOutlineViews shown side by side they contain the same number of rows (this is a prerequisite) and I need to synchronize them when user scrolls using mouse, keyboard or scrollbars so I see the same view portion (or rows).
I'm a newbie in the Cocoa land and I'm unable to find how this can be accomplished
回答1:
You'll want to get the clip view of the NSOutlineView's enclosing scroll view:
NSClipView * clipView = [[outlineView enclosingScrollView] contentView];
...and set its -setPostsFrameChangedNotifications: to YES. Listen for the NSViewFrameDidChangeNotification from that view and respond accordingly.
Note: The nomenclature isn't very clear. Most people's first expectation of -contentView: is that it returns the view being scrolled. The -contentView: method returns the scroll view's NSClipView whereas the -documentView: method returns the actual view being scrolled.
来源:https://stackoverflow.com/questions/5363728/get-scroll-bar-position-of-an-nsscroller-on-the-fly