Re: Interface Builder question
Re: Interface Builder question
- Subject: Re: Interface Builder question
- From: Ondra Cada <email@hidden>
- Date: Tue, 30 Jul 2002 15:03:14 +0200
On Tuesday, July 30, 2002, at 05:03 , Terry Simons wrote:
The fact that when you click on button "X" which is defined in your NIB
file, it calls function "abc" in your code.
It does not. Forget the C++ and Java nonsense. In decent object-oriented
environment, messages are sent instead -- and that's what happens: when
you click on the button, it _sends message "abc" to the object you
connected it to_ (normally, some controller).
I guess the part I'm confused about is that you define your objects in IB.
You don't ever define an object. You define a class, and that is always
done in sources(*). IB offers you to do it in GUI, but that's just a
shortcut -- the appropriate source is generated for you. This service of
IB is actually quite unimportant, and for understanding NIBs you can
forget it and (presume that) all classes are defined entirely writing
sources in PB.
(*) As a matter of fact, ObjC is dynamic enough that you actually can
define a new class programmatically, but it is a real piece of black magic,
and as a newbie do forget it for at least a year ;)
In Java, for instance, you actually have to say...
In Java/Cocoa you don't, incidentally, since Java/Cocoa can use NIBs too ;
)
Nevertheless, you *can* do it the hard way if you wanted to:
"I want a button named 'Button'
id button=[[NSButton alloc] initWithFrame:the_button_desired_size];
and I want it put here in such and such panel,
[[suchAndSuchPanel contentView] addSubview:button];
and I want it to call such and such method."
Send a message! We are in object-oriented environment here.
[button setTarget:theDesiredController];
[button setAction:@selector(theDesiredMessage:)];
In IB, I'm defining my buttons, and making a connection that tells the
button to call function xyz, but I'm not seeing any of the code for the
GUI.
'Course, since there is none! IB is *not* a GUI source generator. It
actually makes those objects and connects them the right way. The complete
network is then loaded into the process; standard library code then
ensures the rest (that if mouse is clicked, the window over which it
happened gets an appropriate message; the window then scans its views, and
forward the message to the one over which the click was, etc).
Is IB required to build an application with Cocoa?
Do I *have* to set my windows up in IB? Can I programmatically define a
window, and manually add buttons to it?
You can do *anything* IB does programmatically. The question is, why, on
earth?
If you have free time enough for playing, do study NSWindow.html,
NSView.html, NSButton.html etc. -- you'll find there all those methods for
cretaing your GUI programmatically.
Ah, and start with ObjC.pdf to understand the differences between ObjC and
C++!
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.