I am very new to cocoa and am trying to understand key value coding.  I have
a document app wherein the NSDocument creates the NSWindowController which
loads a NIB that contains a NSView inside an NSWindow.  The NSWindow
contains the NSView and also a couple of NSTextFields bound to numerical
properties owned by the NSWindowController.  I then display current mouse
coordinates by using the following code in the NSView's mouse move handler:

    extern NSWindowController *wc;

    NSPoint loc = [event locationInWindow];

    loc.x -= [self frame].origin.x;

    loc.y -= [self frame].origin.y;

     [wc setValue:[NSNumber numberWithDouble:(double) loc.y] forKey:@"ypos"
];

    [wc setValue:[NSNumber numberWithDouble:(double) loc.x] forKey:@"xpos"];


This works just fine when wc is a global pointer to the NSWindowController,
which I added out of desperation.  But the following code, which I tried
first, doesnt work for getting wc:


    NSWindow *w = [self window];

    NSWindowController *wc = [w windowController];


    produces NULL for wc



It seems I must be doing something wrong since the NSWindow class have a
property for NSWIndowController isnt documented to  always return NULL.  And
it is hard to believe that the architects of cocoa intended to require that
every bit of shared data be defined as global.


Any chance my overall approach is wrong?  If so, what would be a more
conventional approach for having events processed by a view result in
updates to a control owned by the same window that owns the view?
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to