jump to navigation

Obj-C NSToolBar and Windows created programatically. 21 December 2012

Posted by David Wilson in General.
add a comment

I’ve had this compile error out of XCode. Using the internet to solve it wasn’t that helpful.
I’m Using 10.8, compiling for 10.6 and above.
XCode version is 4.6

ERROR: Can’t have a toolbar in a window with as it’s borderview

In my case the Window is Manually created. To remove the error I had to add “NSTitledWindowMask”

Note that the NSWindow class reference says the following.
windowStyleThe window’s style. It can be NSBorderlessWindowMask, or it can contain any of the options described in “Window Style Masks,” combined using the C bitwise OR operator. Borderless windows display none of the usual peripheral elements and are generally useful only for display or caching purposes; you should normally not need to create them. Also, note that a window’s style mask should include NSTitledWindowMask if it includes any of the others.

There’s the code that creates the window – successfully.

unsigned int styleMask = ( NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSUnifiedTitleAndToolbarWindowMask );
prefsWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 350, 200)

Hope this helps someone else.

Thank you to Glenn for his assistance.

– David