• 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: multiple documents in an app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: multiple documents in an app


  • Subject: Re: multiple documents in an app
  • From: mmalcolm crawford <email@hidden>
  • Date: Sat, 5 Nov 2005 15:22:43 -0800


On Nov 5, 2005, at 3:08 PM, Boyd Collier wrote:

Here is where things now stand: In the method invoked when the user hits the one button in the window showing data to be processed, I tried programmatically creating a window and a controller, as follows:
NSDocument *myOutputDocument = [[NSDocument alloc] init];
NSWindowController *outWindowController;
outWindowController = [outWindowController initWithWindowNibName:@"outputWindow"];
A nib file named outputWindow was of course added to my project, but in the above attempt to use initWithWindowNibName to initialize outWindowController, the window controller is nil. I've also tried to initialize the window controller using a programmatically created window and initWithWindow, but that doesn't work either.
Undoubtedly, I'm overlooking something very simple


I think that's it (or put another way, you're making things too complicated...).

If you have an application controller (an instance of which is created in your Main nib file), and to connected which you have, for example, File menu items to create instances of two different document types -- in this case an Image and a Text document, then you might have action methods for those menu items:


- (IBAction)newImageDocument:(id)sender
{
NSDocumentController *sdc = [NSDocumentController sharedDocumentController];
[sdc openUntitledDocumentOfType:@"image" display:YES];


}

- (IBAction)newTextDocument:(id)sender
{
NSDocumentController *sdc = [NSDocumentController sharedDocumentController];
[sdc openUntitledDocumentOfType:@"text" display:YES];
}



In the project there are two document nib files, TextDocument.nib and ImageDocument.nib. The File's owners are an instances of TextDocument and ImageDocument respectively, and the classes declared and implemented as follows...


mmalc



@interface TextDocument : NSDocument {
    NSData *model;
    id textView;
}
@end


@implementation TextDocument


- (NSString *)windowNibName { return @"TextDocument"; }

// ...

@end


@interface ImageDocument : NSDocument { NSImage *image; IBOutlet NSImageView *imageView; }

- (NSImage *)image;
- (void)setImage:(NSImage *)newImage;

@end

@implementation ImageDocument

- (NSString *)windowNibName {
    return @"ImageDocument";
}

// ...

@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


References: 
 >multiple documents in an app (From: Boyd Collier <email@hidden>)
 >Re: multiple documents in an app (From: mmalcolm crawford <email@hidden>)
 >Re: multiple documents in an app (From: Boyd Collier <email@hidden>)

  • Prev by Date: Re: RunLoops
  • Next by Date: Re: NSPropertyDescription userInfo
  • Previous by thread: Re: multiple documents in an app
  • Next by thread: Re: multiple documents in an app
  • Index(es):
    • Date
    • Thread