M a r k   C r o s b i e

You are in: Simple Edit Panel  Home  Resume  Linux  LEGO  Electronics  Movies  Mac OS X 

Panel Tester
Overview Screenshots Download
Contact Mark at mark@mastincrosbie.com

Simple edit panel

1 January, 2003

A demonstration of how a panel is launched from a main window and can call methods in the main window to change data.

The MyWindowController launches a simple window containing a button and a display field. When the Enter button is pressed, an instance of EntryPanelController is created as a singleton in the enterButton method. The window controller is added to the document. The -updateValue method in the EntryPanelController class is called and passed a reference to the calling object. This allows the EPC to record who called it so it can call methods on its creator.

The MyWindowController registers with the default notification center to receive all notifications of type entryPanelClosed. No object is communicated with the notification. When the notification is received it can clear the value of the epc pointer and thus destroy the reference to the singleton.

The EntryPanelController is created in IB by dropping a panel onto the screen. Two actions are added, okButton and cancelButton. One outlet is added for the NSTextField. The File's Owner is made an instance of EntryPanelController in the IB Info panel under Attributes (!)

When either of the OK or Cancel buttons are pressed a notification is sent of type entryPanelClosing. If OK is pressed then the id of the creator is cast to be of type MyWindowController so we can send a -setValue message to it to change the displayed values. Finally the panel is closed and the window controller is removed.

  1. Don't forget to make File's Owner an instance of MyWindowController in IB.
  2. Must use a method to pass the callers object to the panel. The method may do no other real work.

Closing the panel via the close menu icon does not send a notification to the calling window... Yes, I made the Files Owner the delegate of the Panel and then implemented a -windowWillClose method to catch the close. Alternatively from the NSWindow doc:

The close method posts an NSWindowWillCloseNotification to the default notification center.

Cocoa Programming
An excellent resource on Cocoa programming that covers almost every aspect of development on Mac OS X.
Cocoa Recipes for Mac OS X
A step-by-step guide through developing a multi-document application in Cocoa.
Cocoa Programming for Mac OS X
My first Cocoa book - clearly written guides and excellent coverage of the basics.

© 2002-2004 Mark Crosbie   shareright © 2002 Phlash