PDA

View Full Version : Current Document Change




Duke Leto
Jul 7, 2009, 06:37 AM
I have a tableView in a kind of inspector window, and I want its delegate and dataSource to always be the current document.

I looked at the documentation, and saw no delegate methods for this. I also tried registering for a Key-Value change of current document like this:


[[NSDocumentController sharedDocumentController] addObserver:self forKeyPath:@"currentDocument" options:NSKeyValueObservingOptionNew context:nil];

but it didn't work.

Any suggestions?



jamawa
Jul 7, 2009, 08:13 AM
Have a look at the windowDidBecomeMain: and windowDidResignMain: delegates from NSWindow. You can use these from within your document to update the inspector.

It is what I use to update my document-inspectors and it works nice and neat. There may be other methods as well though.

Cheers,
Jan Martin

Duke Leto
Jul 7, 2009, 09:17 AM
Thanks .. I tried it before, but I tried again because of your advice. Turns out I forgot to specify the name when I added the observer.
:D

Works like a charm!