Re: How to design / structure sheets
Re: How to design / structure sheets
- Subject: Re: How to design / structure sheets
- From: Ken Thomases <email@hidden>
- Date: Fri, 5 Dec 2008 21:17:10 -0600
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 (email@hidden)
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:
This email sent to email@hidden