Re: Windows and views and controls, oh my!
Re: Windows and views and controls, oh my!
- Subject: Re: Windows and views and controls, oh my!
- From: Keary Suska <email@hidden>
- Date: Mon, 05 Sep 2011 09:59:22 -0600
On Sep 5, 2011, at 9:32 AM, William Squires wrote:
> Okay, I'm having a tizzy here. Most of the '...learn MacOS X...' programming books gloss over the nitty-gritty of actually creating and displaying various windows, either assuming they're going to be document windows (as part of a document-based app), or they're just there as part of an example of some other topic.
> While I can create the UI easily enough in IB, what I don't understand is how to actually load, instantiate, and display the window from my view controller object.
> I realize the view controller has to load the nib, but how do I:
>
> 1) make sure the window isn't displayed until all it's views (controls) have had a chance to initialize their default (visual) state properly
> 2) actually display the window, either modally, or not.
> 3) if modal, how does my client code make sure it doesn't return from the operation until the user closes the window (by clicking the close box, or by dismissing it in code from an IBAction tied to an NSButton whose caption is "Done" or some such.)
> 4) Pass information to/from the client code and the view controller?
> 5) Prevent the window from closing (if non-modal) if the contents are 'dirty'?
>
> I prefer to actually make each window and its view controller as a pair, rather than rely on the provided window in MainWindow.xib; this way I'll have to actually know how to tie a .xib and a view controller together, rather than rely on whatever may be in the provided MainWindow.xib in the blank project
Read the "Window Programming Guide" in the API docs (I don't have a web link but Xcode will get you to the right place). It pretty much answers all your questions.
It sounds like you are coming from iOS development--forget what you know about view controllers. The Mac OS X equivalent (NSViewController) is another animal altogether. Specific to your question you are interested in NSWindowControllers. There is also no root controller class such as in iOS.
HTH,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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