Skip navigation.
 
mlRe: Bypassing Interface Builder
FROM : Johnny Lundy
DATE : Thu May 15 22:32:38 2008

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_removed> wrote:

>
> From: Uli Kusterer <witness.of.<email_removed>>
> Subject: Re: Bypassing Interface Builder
> To: Johnny Lundy <<email_removed>>
>
>
> 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

Related mailsAuthorDate
mlBypassing Interface Builder colo May 14, 16:36
mlRe: Bypassing Interface Builder I. Savant May 14, 17:11
mlRe: Bypassing Interface Builder colo May 14, 17:35
mlRe: Bypassing Interface Builder I. Savant May 14, 17:43
mlRe: Bypassing Interface Builder Andy Lee May 14, 17:50
mlRe: Bypassing Interface Builder colo May 14, 17:53
mlRe: Bypassing Interface Builder I. Savant May 14, 17:58
mlRe: Bypassing Interface Builder David Wilson May 14, 17:59
mlRe: Bypassing Interface Builder I. Savant May 14, 18:01
mlRe: Bypassing Interface Builder I. Savant May 14, 18:05
mlRe: Bypassing Interface Builder Gregory Weston May 14, 18:06
mlRe: Bypassing Interface Builder glenn andreas May 14, 18:13
mlRe: Bypassing Interface Builder Wayne Packard May 14, 18:26
mlRe: Bypassing Interface Builder Andy Lee May 14, 18:37
mlRe: Bypassing Interface Builder Stefan Werner May 14, 18:46
mlRe: Bypassing Interface Builder Bill Bumgarner May 14, 19:00
mlRe: Bypassing Interface Builder Boyd Collier May 14, 19:34
mlRe: Bypassing Interface Builder colo May 14, 19:37
mlRe: Bypassing Interface Builder Julius Guzy May 14, 22:05
mlRe: Bypassing Interface Builder Torsten Curdt May 14, 22:49
mlRe: Bypassing Interface Builder colo May 15, 00:53
mlRe: Bypassing Interface Builder Graham Cox May 15, 01:26
mlRe: Bypassing Interface Builder Graham Cox May 15, 01:41
mlRe: Bypassing Interface Builder colo May 15, 02:14
mlRe: Bypassing Interface Builder Johnny Lundy May 15, 02:15
mlRe: Bypassing Interface Builder Graham Cox May 15, 02:29
mlRe: Bypassing Interface Builder I. Savant May 15, 02:43
mlRe: Bypassing Interface Builder Graham Cox May 15, 02:45
mlRe: Bypassing Interface Builder I. Savant May 15, 02:51
mlRe: Bypassing Interface Builder I. Savant May 15, 02:54
mlRe: Bypassing Interface Builder Andy Lee May 15, 03:02
mlRe: Bypassing Interface Builder Graham Cox May 15, 03:02
mlRe: Bypassing Interface Builder Andy Lee May 15, 03:06
mlRe: Bypassing Interface Builder I. Savant May 15, 03:07
mlRe: Bypassing Interface Builder Andy Lee May 15, 03:08
mlRe: Bypassing Interface Builder I. Savant May 15, 03:09
mlRe: Bypassing Interface Builder I. Savant May 15, 03:15
mlRe: Bypassing Interface Builder Andy Lee May 15, 03:29
mlRe: Bypassing Interface Builder Julius Guzy May 15, 03:35
mlRe: Bypassing Interface Builder I. Savant May 15, 03:37
mlRe: Bypassing Interface Builder Johnny Lundy May 15, 04:33
mlRe: Bypassing Interface Builder Julius Guzy May 15, 04:36
mlRe: Bypassing Interface Builder Johnny Lundy May 15, 04:54
mlRe: Bypassing Interface Builder Graham Cox May 15, 05:43
mlRe: Bypassing Interface Builder Uli Kusterer May 15, 07:50
mlRe: Bypassing Interface Builder Uli Kusterer May 15, 07:55
mlRe: Bypassing Interface Builder Uli Kusterer May 15, 08:15
mlcocoa mentoring (was Re: Bypassing Interface Builder) Torsten Curdt May 15, 15:36
mlRe: cocoa mentoring (was Re: Bypassing Interface Builder) Paul Bruneau May 15, 15:47
mlRe: cocoa mentoring (was Re: Bypassing Interface Builder) Uli Kusterer May 15, 16:08
mlcocoaheads frankfurt (was Re: cocoa mentoring) Torsten Curdt May 15, 16:44
mlRe: cocoa mentoring (was Re: Bypassing Interface Builder) Torsten Curdt May 15, 16:51
mlRe: Bypassing Interface Builder Andy Lee May 15, 17:11
mlRe: Bypassing Interface Builder Johnny Lundy May 15, 18:40
mlRe: cocoa mentoring (was Re: Bypassing Interface Builder) Dennis Munsie May 15, 19:34
mlRe: Bypassing Interface Builder Paul Sargent May 15, 20:07
mlRe: Bypassing Interface Builder Uli Kusterer May 15, 20:48
mlRe: Bypassing Interface Builder Shawn Erickson May 15, 22:20
mlRe: Bypassing Interface Builder Shawn Erickson May 15, 22:30
mlRe: Bypassing Interface Builder Johnny Lundy May 15, 22:32
mlRe: cocoa mentoring (was Re: Bypassing Interface Builder) Torsten Curdt May 15, 23:03