One final reply and I will have cluttered up this list enough for now. I thank everyone who took the time to help me.

On May 15, 2008, at 3:06 PM, [EMAIL PROTECTED] wrote:


From: Uli Kusterer <[EMAIL PROTECTED]>
Subject: Re: Bypassing Interface Builder
To: Johnny Lundy <[EMAIL PROTECTED]>


Am 15.05.2008 um 18:40 schrieb Johnny Lundy:
1. Create the class, the .h and .m files.
2. Code the ivars, their @property directives, and their @synthesize
directives.

3. Write 2 instance methods plus the -init method. There are no
class methods, and no IBOutlets.


 Just like you'd do without NIBs, yes.

4. Write an -init method that doesn't instantiate anything.

 Well, init gets called when your object is instantiated, it doesn't
instantiate the object itself. Of course, init can instantiate *other*
objects that your object needs, like an NSTextField would probably
instantiate an NSMutableString object to hold whatever text it's
supposed to display.

5. There is no +initialize method, as I don't understand it. When I
have tried to use it, it complains I can't refer to ivars.

 +initialize is a class method, hence the "+". It is kind of a
constructor for the class (as opposed to the -init methods that get
called on objects. This was one of the harder parts in Objective C, to
teach oneself to read + to mean "class method" and - to mean "object/
instance method".

6. Compile.
7. In IB, make an NSTextField and read in my class header file.

 Not related, and as others have said, IB3 reads your classes
automagically as soon as you save them.


Really? Heh- I have been wasting a lot of time reading the header into IB every time I modify it. This is great to know.


8. In IB, drag out an NSObject and give it the class name of my new
class. I did NOT control-drag anything to anything, and there are no
IBOutlets in my code.

 If that is all you did, then an object of your class was never
instantiated. The only thing you got was an NSObject. The least you'll
have to do is go to the "identity" pane of the inspector for this
instance and type the name of your class into the "custom class" field.

When I say "give it the class name", I mean I entered my class name in the "Class Identity" pane of IB.



Somehow, doing the above steps must have created an instance of my
class, as one instance method can call another.

 What do you mean by 'one instance method can call another' ? Who is
calling whom, how?

I mean that when my app launches, this class' -init method invokes

[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTime:) userInfo:nil repeats:YES];


and that NSTimer method successfully invokes my other instance method using the selector updateTime:

- (void) updateTime:aTimer
{
[self.endTime years:NULL months:NULL days:NULL hours:&hours minutes:&minutes seconds:&seconds sinceDate:[NSCalendarDate calendarDate]];
        self.timeString = [NSString stringWithFormat:
                                           @"%.2d:%.2d:%.2d", hours, minutes, 
seconds];
}

If there was no instance of the class, this could not happen, right? So the class must have been instantiated, and since I did not code any alloc or new method invocations, the instantiation had to have happened in IB.


If you just created this object, and nobody else
has an outlet pointing to it, then while it was instantiated, nobody
can call a method on it, because nobody has a pointer to it. Someone
needs to have an outlet or a binding to it to call a method on it (or
if your object has an action, then it'll probably pass a pointer to
itself as the sender of that action, so whoever is the target could
send a message back then, etc. etc.)



AHA! So to let an instance method in class A message an instance method in class B, and the only instance of the CLASS B that I have is the NSObject in Interface Builder, I HAVE to make an IBOutlet in Class A (the class that needs to send the message) and point it to the instance of class B (the class that needs to receive the message)! Got it.

What a relief, to finally understand it after all this time. That is what I meant by "the instance doesn't have a name and I need a name to send messages to it." It gets a name from an IBOutlet. I did not want to code an "alloc] init]" for fear that would make a second instance.

And this is exactly what you said in a later paragraph -

What you need to do
instead is add an outlet to whatever object is sending this message,
and control-drag to make IB aware that you want this outlet to point
at that particular instance.

Got it. Many many thanks to you for taking the time.

Johnny


Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de

_______________________________________________

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