Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I did something similar to two NSTableViews, scrolling of one would make second scroll. </p> <p>Here is the code for that:</p> <p><em>MyScrollView.h</em></p> <pre><code>#import &lt;AppKit/AppKit.h&gt; #import "AppDelegate.h" @interface MyScrollView : NSScrollView @property (strong) AppDelegate *app; @end </code></pre> <p><em>MyScrollView.m</em></p> <pre><code>#import "MyScrollView.h" //#define LogRect(RECT) NSLog(@"%s: (%0.0f, %0.0f) %0.0f x %0.0f", #RECT, RECT.origin.x, RECT.origin.y, RECT.size.width, RECT.size.height) @implementation MyScrollView @synthesize app; - (void)reflectScrolledClipView:(NSClipView *)aClipView{ [super reflectScrolledClipView:(NSClipView *)aClipView]; //post a notification app=[[AppDelegate alloc] init]; if (app) { [[NSNotificationCenter defaultCenter] postNotificationName:@"scrolled" object:aClipView]; } } @end </code></pre> <p><em>AppDelegate.h</em></p> <pre><code>#import &lt;Cocoa/Cocoa.h&gt; @interface AppDelegate : NSObject &lt;NSApplicationDelegate&gt; @property (assign) IBOutlet NSWindow *window; @property (strong) IBOutlet NSTableView *aTableView; @property (strong) IBOutlet NSTableView *bTableView; @property (strong) IBOutlet NSTableView *cTableView; @property (strong) IBOutlet NSView *aView; @property (strong) IBOutlet NSView *bView; @end </code></pre> <p><em>AppDelegate.m</em></p> <pre><code>#import "AppDelegate.h" @implementation AppDelegate /* Unwanted methods are not shown here, like delegates, datasource, init etc */ -(void)scrollTable:(NSNotification *)aNotification{ NSPoint globalLocation = [NSEvent mouseLocation ]; NSPoint windowLocationForA = [[aView window ] convertScreenToBase:globalLocation ]; NSPoint viewLocationForA = [aView convertPoint: windowLocationForA fromView: nil ]; NSPoint windowLocationForB = [[bView window ] convertScreenToBase:globalLocation ]; NSPoint viewLocationForB = [bView convertPoint: windowLocationForB fromView: nil ]; if (NSPointInRect(viewLocationForA, [aView bounds])) { // i scrolled on A NSLog(@"Scrolled A"); if ([[[aTableView superview]superview] isEqualTo:[[aNotification object] superview]]) { [bTableView scrollRectToVisible:[[aNotification object] documentVisibleRect]]; [cTableView scrollRectToVisible:[[aNotification object] documentVisibleRect]]; } } else if (NSPointInRect(viewLocationForB, [bView bounds])) { // i scrolled on B NSLog(@"Scrolled B"); if ([[[bTableView superview]superview] isEqualTo:[[aNotification object] superview]]){ [aTableView scrollRectToVisible:[[aNotification object] documentVisibleRect]]; [cTableView scrollRectToVisible:[[aNotification object] documentVisibleRect]]; } } else{ // i scrolled on C NSLog(@"Scrolled C"); if ([[[cTableView superview]superview] isEqualTo:[[aNotification object] superview]]){ [aTableView scrollRectToVisible:[[aNotification object] documentVisibleRect]]; [bTableView scrollRectToVisible:[[aNotification object] documentVisibleRect]]; } } } -(void)awakeFromNib{ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scrollTable:) name:@"scrolled" object:nil]; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload