• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Newbie Connections Question - Sorry!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie Connections Question - Sorry!


  • Subject: Re: Newbie Connections Question - Sorry!
  • From: Nate Murray <email@hidden>
  • Date: Mon, 13 Sep 2004 21:12:42 -0700

Okay, I totally appreciate all the stuff you've been saying, but I feel like the response may be a little too basic than what I was looking for.
So what you're telling me is that the only way for a dynamically created object to access any of the objects created by the Nib is to have it directly passed to it? That seems a bit harsh. I want it to access all my other methods in my other objects just like the ones that are connected through the Nib connections in interface builder.


I dont mean to bog down the newsgroup with such simple concepts as the difference between objects and classes or how to [[alloc] init] a new object. I just want to access methods in other objects with my new dynamic objects!



On Sep 13, 2004, at 8:40 PM, Harilaos Skiadas wrote:

Exactly. What you want to do is, from the appropriate place in AdamController, have something like

AdamSprite *mySprite;
mySprite = [[AdamSprite alloc] init];

This will create an instance of AdamSprite called
mySprite, and your AdamController knows about it.
Actually, you first need to tell your AdamController
about the AdamSprite class by adidng #include
"AdamSprite.h" at the beginning of AdamController.m

You might want to write your own init method to
initialize the special variables that AdamSprite might
have. Now, whenever you want mySprite to do something,
all you have to do is call the appropriate method by
something like

[mySprite doCoolStuff];

if you want it to know about the view the controller
knows about, which I will call myView, I think you
could do (not entirely sure about this) something
like:

[mySprite doCoolStuffWithView:myView];

and then you will have access to myView within the
method doCoolStuffWithView: of AdamSprite (which of
course you should implement).


Lets up the ante a little: Not that I expect everyone else to write my code for
me, but one of >the
things Im specifically looking to do is access the
[NSView bounds]
method. (ie [AdamView bounds])
I need to moveSprite method located in AdamSprite to
know what the
bounds of my custom subclass of NSView (AdamView)
are. So that >way we
can keep the sprite on the screen.


well, once it knows about the view, it can learn anything about the view too, with [myView bounds]. the one thing to keep in mind when calling these methods, is that you always have to call them for the instances of a class. They are instance methods, not class methods. alloc is a class method, so [AdamClass alloc] creates a new instance of AdamClass and returns it, so with something like myAdamClassInstance = [AdamClass alloc];

myAdamClassInstance now points to a newly created
instance of class AdamClass. Then you would usually
need to further initialize it to set initial values to
variables etc, which would be done with something like
[myAdamClassInstance init];

init is an instance method.
Then you are responsible for these instances, and you
should release them when you are done.
I can tell you more about this off the list, it would
probably bore most of the list members.
Indeed this is very basic stuff, I would recommend you
get your hands on some of the excellent books on
Objective-C and Cocoa programming that are out there
and dig in. My personal favorites, and generally
considered among the best I think, are Stephen
Kolchan's "Programming in Objective-C" and Aaron
Hillegass' "Cocoa programming for Mac OS X". The first
one teaches you about classes and instances, and
object-oriented programming in general, assuming
little or no knowledge, while the second shows you how
to use the tools in cocoa, and how to work with XCode
and IB. IMHO they are both must-haves, especially for
newbies.
my 2 cents

Thanks for your help guys,

-Nate

Haris

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


_______________________________________________ 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
References: 
 >Re: Newbie Connections Question - Sorry! (From: Harilaos Skiadas <email@hidden>)

  • Prev by Date: Re: Newbie Connections Question - Sorry!
  • Next by Date: how to composite NSBezierPath and text on an image
  • Previous by thread: Re: Newbie Connections Question - Sorry!
  • Next by thread: Re: Newbie Connections Question - Sorry!
  • Index(es):
    • Date
    • Thread