Current Document Change

Discussion in 'Mac Programming' started by Duke Leto, Jul 7, 2009.

  1. Duke Leto macrumors regular

    Mar 17, 2008
    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?
  2. jamawa macrumors newbie

    Jul 7, 2009
    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.

    Jan Martin
  3. Duke Leto thread starter macrumors regular

    Mar 17, 2008
    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.

    Works like a charm!

Share This Page