Re: Getting a NSView pointer from a nib
Re: Getting a NSView pointer from a nib
- Subject: Re: Getting a NSView pointer from a nib
- From: Ondra Cada <email@hidden>
- Date: Fri, 28 Apr 2006 15:44:31 +0200
Milen,
On 28.4.2006, at 15:27, Milen Dzhumerov wrote:
I was wondering today if is possible to retrieve a NSView* from a nib.
Absolutely. One of the most common tasks. Read the documentation and
study "outlets".
I'm also wondering how am I going to connect the separate nib with
the rest of the application...
... and actions, and bindings (I'd recommend to understand outlets/
actions first, and only when you do, begin on bindings, for it is a
slightly different concept, but YMMV).
I suppose I have to do everything programmatically.
You *can* do everything programmatically, but rarely enough have to.
Definitely not in this case. The one thing you have to do
programmatically is adding the view into the window (given they both
came from different NIBs).
PS. I should note that I'm not quite familiar with the whole Nib
concept so I'm trying to apply techniques from other programming
environments (I'm basically thinking of Nib files as files
describing interface elements which I can instantiate later
programmatically somewhere in the application a la Glade from the
GTK+ environment).
This is a good start, *in a sense* it is right.
The conceptual and deep difference is that the "description" takes
form of persistent objects. For example, the "description" of a
window *is the very* window object, serialized out into the NIB file.
Conceptually, presume for a moment you would make the complete
interface programmatically, instantiating all GUI objects by code
(like, [[NSWindow alloc] initWith....]), setting their attributes
programmatically (like, [window setFrame:...] or [view
setTooltip:...]), and setting the appopriate relationships between
them programmatically (like, [window setContentView:view]).
When done, you would use archivation API to make the whole network of
objects persistent (like, [NSArchiver archiveRootObject:rootWindow
toFile:...]).
Now, you could throw out all the GUI-creation code as something which
would not be needed anymore: the archived file could be just
unarchived next time the application is launched to create the very
same GUI without all the hassle. And this result file would be,
actually(*), a NIB.
(*) with some extra features which NIB allows for--like File's Owner
or First Responder--not available in your makeshift scheme, of course.
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden