Creating an Accessory NSView
An accessory view is an NSView that you provide to the NSSavePanel object. The NSSavePanel object is then automatically incorporated into the Save sheet when it is displayed. Many applications use accessory views to let the user choose options when saving.
IB has direct support for creating accessory views. It allows you to create standalone views — views that aren’t displayed in a window, but that are designed to be placed into windows as the need arises. In the next step, we’ll create a simple NSView instance that will be used as a container. We will then place the desired controls in this NSView and group it in a box. Finally, we will take the id of this view and pass it to the NSSavePanel object.
We’ll start by making the necessary changes to
Controller.h
. Then we’ll create
the accessory view and make connections in IB. Finally,
we’ll implement the necessary method in
Controller.m
to allow us to specify the file
type.
Insert the
formatBox
andformatMatrix
outlets and thesavePanel
instance variable intoController.h
:@interface Controller : NSObject { IBOutlet id graphView; IBOutlet id prefController; IBOutlet id formatBox; IBOutlet id formatMatrix; NSSavePanel *savePanel; }
Insert the following setFormat: action method declaration into
Controller.h
:- (IBAction)setFormat:(id)sender;
Save
Controller.h
.Activate IB and make sure that
MainMenu.nib
is the active window.Read (parse) the updated Controller class definition into
MainMenu.nib
.An easy ...
Get Building Cocoa Applications: A Step by Step Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.