I am using (NSPrintOperation *)printOperationWithView:(NSView *)aView printInfo:(NSPrintInfo *)aPrintInfo method to print a view in my OS X app. All works as expected. Is there a way to catch the event when the user has cancelled the print operation by clicking on the "cancel" button on the print panel? I have been searching here, Apple's printing programming guide and the web but found nothing so far. Does anyone know how?
Asked
Active
Viewed 344 times
1 Answers
0
Solved it! I added a selector to print operation method to catch the event when the printPanelDidEnd:
[printOp runOperationModalForWindow:myWindow delegate:self didRunSelector:@selector(printPanelDidEnd:returnCode:contextInfo:) contextInfo:nil];
and then:
- (void)printPanelDidEnd:(NSPrintPanel *)printPanel returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
if (returnCode == NSCancelButton) {
NSLog(@"Cancel button was selected");
}
}

DORI
- 54
- 1
- 8
-
The return value of `NSPrintOperation.run()` also contains `false` if the user has canceled the print dialog. https://developer.apple.com/documentation/appkit/nsprintoperation/1532039-run – Felix Mar 13 '20 at 15:12