• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: MainMenu.nib - MyDocument.nib bindings question...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MainMenu.nib - MyDocument.nib bindings question...


  • Subject: Re: MainMenu.nib - MyDocument.nib bindings question...
  • From: "R. Matthew Emerson" <email@hidden>
  • Date: Wed, 23 Aug 2006 20:25:06 -0400


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.myAtt 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


  • Follow-Ups:
    • Re: [SOLVED] - MainMenu.nib - MyDocument.nib bindings question...
      • From: Kam Dahin <email@hidden>
References: 
 >MainMenu.nib - MyDocument.nib bindings question... (From: Kam Dahin <email@hidden>)

  • Prev by Date: Re: MainMenu.nib - MyDocument.nib bindings question...
  • Next by Date: Re: [SOLVED] - MainMenu.nib - MyDocument.nib bindings question...
  • Previous by thread: Re: MainMenu.nib - MyDocument.nib bindings question...
  • Next by thread: Re: [SOLVED] - MainMenu.nib - MyDocument.nib bindings question...
  • Index(es):
    • Date
    • Thread