On Dec 5, 2008, at 12:20 PM, Mike Chambers wrote:

I am creating a custom sheet for my application which allows a user to
add an item to iCal. However, it is not clear to me the best way to
structure my code.

[...]

The Sheet is contained in a separate NIB / XIB file as an NSWindow.

I see two potential options:

1. Instantiate the sheet directly from my App controller and add all
sheet logic to that controller.

2. Create a class for the sheet, and add sheet logic to that class.
Controller would instantiate the class, tell it to open sheet, and
then get notified when it was closed.

Any input on which approach is the better way (or the Cocoa way)? If
#2, do I hook the nib up the its controller class in the same way I do
with my main controller and its nib?

Yes, I would recommend option 2, also.

In the main nib, the application is usually the File's Owner. Also, it's fairly common for the application controller to be instantiated as an object within the nib.

In a nib for a separate window, that's not the way it's done. The recommended approach is to use a custom subclass of NSWindowController, and let that object load the nib. The window controller will be instantiated in code, not in the nib -- usually by a higher-level controller like your app controller. The window controller will specify itself as the owner of the nib, so when setting up the nib you configure File's Owner to be a stand-in for that object. Basically, you set the class of File's Owner to be your custom class. Don't forget to connect the 'window' outlet of File's Owner to the window in the nib.

Cheers,
Ken

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to