开发者

Using NSPrintOperation in Cocoa

开发者 https://www.devze.com 2023-02-05 09:49 出处:网络
I\'m writing a document based Mac OSX application, and I\'m reading a tutorial that talks about using the NSPrintOperation (by d开发者_运维知识库efault, pressing print in my application right now give

I'm writing a document based Mac OSX application, and I'm reading a tutorial that talks about using the NSPrintOperation (by d开发者_运维知识库efault, pressing print in my application right now gives the error:

   printOperationWithSettings:error: is a subclass responsibility but has not been overridden.

So I'm told to use the following:

    - (NSPrintOperation *)printOperationWithSettings:(NSDictionary *)ps error:(NSError **)e;
{
    NSPrintInfo *printInfo = [self printInfo];
    NSPrintOperation *printOp = [NSPrintOperation printOperationWithView:MyView
                                                               printInfo:printInfo];
    return printOp;

(where MyView is the name of the view i want printed. My question is where do i name that view? In Interface Builder? I tried 'self' and that threw an error. I'm still learning cocoa so I'm confused. The instances in Interface Builder are just NSView's and are named View (not unique). Any help?


In your document's .h file, add the following:

@interface MyDocument : NSDocument {
    IBOutlet NSView      *myView;
}

@end

(If you actually have a custom subclass of an NSView, or the view you intend on printing is a more particular kind of view (for example, NSTableView), you would probably change the type to be that type instead of the generic NSView).

Then, in Interface Builder, in the nib file, you will most likely Control-drag from the "File's owner" object to the view you intend to print. When you see the view highlighted, and let go, you should get a popup menu where you can choose myView. Now you've hooked up the wires, so to speak, so you can have a reference to that particular view in the rest of your code.

0

精彩评论

暂无评论...
验证码 换一张
取 消