🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #428

Re: Need help with multiple nib file programming...

#428
From: Andrew Loewenstern
Date: Mon, 03 Aug 1992 17:53
63 lines
2460 bytes
In article <1992Aug1.195812.831@afs.com> greg@afs.com writes:
>You have to do it through the app (your own subclass) or the app's  
>delegate (your own delegate), either of which needs an instance variable  
>for the pieces that need to intercommunicate. Then each instance variable  
>needs a method that simply returns the object's ID. For example:
>
>@interface AppDelegate
>{
>	id object1;
>	id object2;
>}
>- object1;
>- object2;
>@end
>
>Then in code you say
>#import AppDelegate.h
>....
>	[[[NXApp delegate] object1] doSomeMethod:sender];
>....

What I do (fairly often I might add...) is add a +new method to an
object that will be needed all over the application.  This only works
if you want to have a single instance of this object in the app (like
specific controllers and such...).  Add a method like this to your
class (but don't put it in the header file...):


static id myself		/* the one instance of this class */

+ new
{
  if(!myself)
      myself = self = [super new]; /* put additional initialization in */
				   /* the -init method. */
  else
    self = myself;
  
  return self;
}


When you need this object, just call [MyClass new].  If the object
does not exist yet, it will be created (be lazy...), if it already
exists, then it will just give you back it's id.

Now for messaging between nibs, put this in the file's owner class for
the nib with the loading code in the init method and put the object1,
object2, etc... methods in the nib's owner instead of cluttering up
the app delegate (which is usually too cluttered up as it is...).

So instead of [[[NXApp delegate] object1] doSomeMethod:sender]; you
will do [[[MyNibOwner new] object1] doSomeMethod:sender];.

The +new method is useful for a lot of situations, and the above just
helps organize things.


andrew
-- 
andrew@cubetech.com
Andrew Loewenstern      | "Remember what the doormouse said...
Cube Technologies, Inc. |  Feed your head."  - Jefferson Airplane
Technical Details
Message-ID: <1992Aug3.175348.9033@cubetech.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!gatech!rpi!psinntp!psinntp!cubetech.com!imladris!andrew
References: <1992Jul29.184519.22474@aio.jsc.nasa.gov> <1992Aug1.195812.831@afs.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.next.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!gatech!rpi!psinntp!psinntp!cubetech.com!imladris!andrew
From: andrew@cubetech.com (Andrew Loewenstern)
Subject: Re: Need help with multiple nib file programming...
Message-ID: <1992Aug3.175348.9033@cubetech.com>
Organization: Cube Technologies, Inc.
References: <1992Jul29.184519.22474@aio.jsc.nasa.gov> <1992Aug1.195812.831@afs.com>
Date: Mon, 3 Aug 1992 17:53:48 GMT
Lines: 64