Re: [SOLVED] - MainMenu.nib - MyDocument.nib bindings question...
Re: [SOLVED] - MainMenu.nib - MyDocument.nib bindings question...
- Subject: Re: [SOLVED] - MainMenu.nib - MyDocument.nib bindings question...
- From: Kam Dahin <email@hidden>
- Date: Wed, 23 Aug 2006 17:34:37 -0700
"You can try binding to Shared Application with a key path of
@"mainWindow.windowController.document.myArrayController.selection.myA
tt
ribute".
(Assuming that you have a reference to the array controller in your
document class, of course.)"
Matthew,
Thanks - specifying the full key path did it!
I knew it had to be something simple, but I just couldn't figure it out.
Regards,
k
On Aug 23, 2006, at 5:25 PM, R. Matthew Emerson wrote:
On Aug 23, 2006, at 5:35 PM, Kam Dahin wrote:
> I have a main window in my MyDocument.nib with a NSTableView, that
> gets it's contents from a NSArrayController and is working fine.
>
> I have a NSPanel that is a triggered from a MenuItem in my
> MainMenu.nib and I would like the panel to display information
> about the currently selected row in the NSTableView. I would like
> to bind the fields in my NSPanel to the NSArrayController that I am
> using for my TableView. Can anyone point me at a good tutorial, or
> example of how to make this work using bindings? It seems like a
> simple thing to do, but I haven't been able to find a good example
> of how to make this happen.
It sounds like your problem is that you need a key path to refer to
the current document object.
You can try binding to Shared Application with a key path of
@"mainWindow.windowController.document.myArrayController.selection.myA
tt
ribute".
(Assuming that you have a reference to the array controller in your
document class, of course.)
That may very well work, but I am not sure that everything in that
long key path is KVO compliant.
Another way to do it would be to add code to your application
delegate that keeps track of the current document, and exposes that
in a KVO-compliant way. You can then bind to Shared Application with
a key path of
@"delegate.currentDocument.myArrayController.selection.myAttribute".
Something like this, then, perhaps (may be syntax errors, etc.):
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject {
NSDocument *currentDocument;
}
- (void)setCurrentDocument:(NSDocument *)document;
- (NSDocument *)currentDocument;
@end
@implementation AppDelegate
- (void)awakeFromNib
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector
(windowDidBecomeMain:)
name:NSWindowDidBecomeMainNotification
object:nil];
}
- (void)setCurrentDocument:(NSDocument *)document
{
if (currentDocument != document) {
[document retain];
[currentDocument release];
currentDocument = document;
}
}
- (NSDocument *)currentDocument
{
return currentDocument;
}
- (void)windowDidBecomeMain:(NSNotification *)note
{
[self setCurrentDocument:[[NSDocumentController
sharedDocumentController] currentDocument]];
}
- (void)applicationWillTerminate:(NSNotification *)note
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)dealloc
{
[currentDocument release];
[super dealloc];
}
@end
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden