Designing a Sheet in Interface Builder

Quick tip time! This is an anecdote from a libre project I’m working on, specifically Auctions.

One of the things I am doing right now is implementing the Cocoa/Mac UI. I’m writing a flow using sheets for signing in to accounts. I had a lot of issues making the sheet accept input; it just wouldn’t let any of its fields become the first responder.

Poking around DuckDuckGo, I found a Stack Overflow question that seemed pretty interesting, and the answer was to override NSPanel‘s canBecomeKeyWindow method to return YES. I did some searching around in Apple’s Developer Documentation to see how the system determines when a window can become a key window, and I found this nugget:

A window that uses NSWindowStyleMaskBorderless can’t become key or main, unless the value of canBecomeKeyWindow or canBecomeMainWindow is YES. Note that you can set a window’s or panel’s style mask to NSWindowStyleMaskBorderless in Interface Builder by deselecting Title Bar in the Appearance section of the Attributes inspector.

Apple Developer Documentation

I had turned off Title Bar in Interface Builder as I thought it should be disabled since the window would be shown as a sheet. I re-enabled Title Bar, and voila! The sheet worked perfectly, and did not have a title bar when displayed as a sheet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s