Apple has changed decades ago by introducing to the world single window applications. Ever since we have seen tremendous applications all taking advantage of this form. Functionality that compliments that form are things like window sheets, those cool pop-under windows that slide up and down from the top of the application top bar. Sheets magically show us controls when we need them and then whoosh them away when we don’t.
Not surprisingly Apple has built in controls for system level windows to use this wonderful technology. However its not very commonly known how to do so with common system windows like Print Dialogue boxes and page layout windows. I recently started working on a Cocoa project where the goal was to keep everything contained in the single window concept.
It took me a while to figure out how to use the delegates that Apple built into these two windows in order to have them display by default as a sheet. I hope that this article helps others struggling with the same problem.

First create a custom class in my case I created a subclass of NSObject called Print_View.m/h.
Print_View.h : Subclass of NSObject
#import <Foundation/Foundation.h>
@interface Print_View : NSObject
{
IBOutlet id PrintView;
IBOutlet id window;
IBOutlet id MainWindow;
}
- (IBAction)pagesetup:(id)sender;
- (IBAction)print:(id)sender;
@endNotice here that I created 3 outlets and 2 senders. The PrintView outlet should be connected to the view, or text element in the NSWindow that you want to print. This is important, the delegate will not work until you declare the thing that the application will be printing.
the window and MainWindow outlets need to be connected to the main window in your XIB file. Finally the senders need to be connected to the File > Print, and File > Page Setup menu items respectively.


Print_View.m : Subclass of NSObject
#import "Print_View.h"
@implementation Print_View
- (IBAction)print:(id)sender {
NSPrintOperation* printOperation = [NSPrintOperation printOperationWithView:PrintView];
[printOperation setCanSpawnSeparateThread:YES];
[printOperation runOperationModalForWindow:window delegate:window didRunSelector:nil contextInfo:nil];
}
- (IBAction)pagesetup:(id)sender {
NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];
NSPageLayout *pageLayout = [NSPageLayout pageLayout];
[pageLayout beginSheetWithPrintInfo:printInfo modalForWindow:window delegate:MainWindow didEndSelector:@selector(pageLayoutDidEnd:returnCode:contextInfo:) contextInfo:nil];
}
- (void)pageLayoutDidEnd:(NSPageLayout *)pageLayout returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
if (returnCode == NSOKButton)
{
}
}
@endAs you can see the above code triggers the system dialogue boxes and treats them as sheets to the window with a delegate of MainWindow. You will also notice that the page setup has a function called pageLayoutDidEnd this is a place where you can enable custom functionality after the OK button is pressed, if you do not wish any other functionality then the window exits and the page prints.
AI Usage Transparency Report
Pre-AI Era · Written before widespread use of generative AI tools
AI Signal Composition
Score: 0.05 · Low AI Influence
Summary
A guide on how to use delegates to display system windows as sheets in a Cocoa project.
Related Posts
Fontrestore, Apple’s fix for your fonts
FontAgent Pro is a great font management solution for OS X. One of the best things about it is that its 100% cloud based. You can run the entire thing hosted in their cloud instance or you can run it on your own server. It's a great solution for font management, and does everything from managing your font licenses, users, libraries, and sets. The one problem however is the fact that when deploying a new font solution, you find yourself in a quandary over the right way to deploy it....
Cocoa Control: Horizontal Graph View
I have been struggling for years trying to get NSRect to play nicely and draw a cool looking responsive graph in a Cocoa application. I was trying to create a controller that could be used with iOS and Mac OSX, but the two platforms had too many internal differences for one controller class to make sense. The discrepancies between the frameworks made it difficult to share code between the two platforms, forcing me to maintain separate implementations for each.
Cocoa App: Animal Age
In an effort to learn more about Objective-C programming, I have created a simple OSX Application that mimics one of my more popular widgets, the Dog Age Widget. Its a native Objective-C Animal Age calculator that allows you to convert the ages of various animals against human lifespans and see life expectancies based on different breeds of animals. The application is designed to be straightforward and easy to use, with a simple interface that makes it accessible to users who are new to programming.
Cocoa Control: iTunes Style Application
Recently I have become more and more interested with the wonderful world of Objective-C and C. For the last couple years I have been a hobbyist developer and still am today. I never really felt that my development skills had reached any level of real skill and so I have been an active member on websites like Stack overflow, Apple Developer Forums and more asking over and over the answers to what were probably very simple issues and questions that I hurdled over while learning.