Current Document Change

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

  1. macrumors regular

    Joined:
    Mar 17, 2008
    #1
    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:

    Code:
    [[NSDocumentController sharedDocumentController] addObserver:self  forKeyPath:@"currentDocument"  options:NSKeyValueObservingOptionNew  context:nil];
    
    but it didn't work.

    Any suggestions?
     
  2. macrumors newbie

    Joined:
    Jul 7, 2009
    #2
    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
     
  3. thread starter macrumors regular

    Joined:
    Mar 17, 2008
    #3
    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!
     

Share This Page