Tips for Developing Multiple Windowed Mac Applications

I have read several books on Mac development but cannot find the information I am looking for.

All books describe how to create floating windows or panels, but never mention how to make them all in one window. Below is a simplified example of what I'm creating to be created:


Basically, there will be three windows; A selector box with radio buttons for choosing which NSDocument is currently being used - a box below it with buttons that show different windows on the right that allow you to view and manipulate certain data.

As an example, each NSDocument can have a color value that can be set in the window shown by clicking on image A, and some text strings that can be set in the window shown in viewer B.

So the questions:

  • Is it appropriate to use one NSDocument subclass for each DoC # 1 and DoC # 2?
  • What classes should I use to configure the application as shown? NSWindowController? NSWindow? NSPanel?

I'm only looking for a reading guide, so any pointers are appreciated.


To clarify this, I want to have a table view where the buttons are (view A and B), and by clicking on them, they will make another window / view change its contents.

This is similar to the split view in the iPad settings app, with a tabular view on the left, and changing when you tap on the right.

The radio buttons are only shown to illustrate that I need more than one document. I'm assuming I need more than one to handle this? Or maybe I should place them in the same NSDocument? Somehow it doesn't seem right.


source to share

2 answers

To achieve what you want, you need one window ( NSWindow

), one window controller, and different views, each with its own view controller. There are several ways to set this up, depending on your requirements:

  • You must have at least 3 views (instances NSView

    ): one for document class selection, one for selection and one for content. Each view is controlled by a view controller (instance NSViewController

    ). Alternatively, you can turn off split views ( NSSplitView

    ) so that your user can change the size of the properties available for each view.

  • You have one window with a window controller. If you choose a document-based app template in Xcode, Xcode will generate a subclass NSDocument

    that you can use as your window controller (or use Core Data, and Xcode will generate a subclass NSPersistentDocument

    with all the bells and whistles you need to access the main data to save documents).

So back to your questions:

1: Yes, but depending on your requirements. If DoC # 1 is a completely different thing from DoC # 2, you may need to re-evaluate. For example, DoC # 1 may have completely different persistent requirements than # 2.

2: There is no single scenario here, but it worked for me: take a project template for a document based application (with or without Core Data). Use the generated subclass NSDocument

(or NSPersistentDocument

) as your window controller. Use NSView

to implement views in your window, where each view is controlled by its own controller, which is an instance NSViewController




I know this is an old question, but the way to do it the way you want would be to use: ContainerViews and set their segue embedding as the view controllers you want.



All Articles