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
To achieve what you want, you need one window (
), 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
): one for document class selection, one for selection and one for content. Each view is controlled by a view controller (instance
). Alternatively, you can turn off split views (
) 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
that you can use as your window controller (or use Core Data, and Xcode will generate a subclass
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
) as your window controller. Use
to implement views in your window, where each view is controlled by its own controller, which is an instance
source to share