• 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: Re : Newbie Q: equipping an NSDocument subclass with a window controller (2)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Re : Newbie Q: equipping an NSDocument subclass with a window controller (2)


  • Subject: Re: Re : Newbie Q: equipping an NSDocument subclass with a window controller (2)
  • From: Sherm Pendley <email@hidden>
  • Date: Wed, 12 Oct 2005 14:24:44 -0400

On Oct 12, 2005, at 1:05 PM, email@hidden wrote:

Is BlueWindow a subclass of NSDocument? If so, that is *not* how you
create a new NSDocument.

er, how is it done then ? I used to have a connection between a "Blue
Window" button and this (void) (IBAction, actually) showBlueWindow method. What
should I have connected that button to instead ?

Are you certain that what you need to do is create a new document? It sounds to me like you want to create and display a new window, and associate it with an already-open document.


You mentioned earlier, that you want to connect outlets in your Nib to your document object - so I'm assuming there could be many of these "Blue Windows", one for each document. Otherwise, such connections wouldn't make sense.

If you want the window to be shown immediately when a new document is created, just create and add it in -makeWindowControllers like I mentioned earlier.

If you don't want this window to appear when a new document is created, don't create it in -makeWindowControllers. Instead, move your -showBlueWindow: method to your NSDocument subclass, and connect that menu item to First Responder.

Your -showBlueWindow: method might look something like this:

- (void) showBlueWindow: (id)sender {
    NSWindowController *c;

    // First check for an existing controller for BlueWindow.nib
    NSEnumerator *e = [[self windowControllers] objectEnumerator];
    while (c = [e nextObject]) {
        if ([[c windowNibName] isEqualToString:@"BlueWindow"]) break;
    }

// If none was found, create one and add it
if (nil == c) {
c = [[[NSWindowController alloc] initWithWindowNibName:@"BlueWindow" owner:self] autorelease];
[self addWindowController:c];
}


    // Whether it was newly created or not, show it
    [c showWindow:sender];
}

The general flow is, NSDocumentManager creates a new NSDocument, and then the NSDocument creates and manages its own NSWindowControllers.

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org

_______________________________________________
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


References: 
 >Re : Newbie Q: equipping an NSDocument subclass with a window controller (2) (From: email@hidden)

  • Prev by Date: loadNibNamed, Bindings and retain count
  • Next by Date: SharedFrameworks
  • Previous by thread: Re : Newbie Q: equipping an NSDocument subclass with a window controller (2)
  • Next by thread: iTunes like multipane grid view examples?
  • Index(es):
    • Date
    • Thread