Getting pointer to NSWindowController
Getting pointer to NSWindowController
- Subject: Getting pointer to NSWindowController
- From: Nirias <email@hidden>
- Date: Tue, 7 Oct 2008 22:00:29 -0700
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 (email@hidden)
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:
This email sent to email@hidden