Newbie: Referencing Objects - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Programming Languages & Scripting (/forum-8.html)
+--- Thread: Newbie: Referencing Objects (/thread-2231.html)
Newbie: Referencing Objects - john42 - Oct 25, 2008 10:02 AM
Please read my question, I'm stuck and it doesn't really have anything to do with the iPhone, more with Objective-C in general.
I create a UIBarButtonItem and in the course of that I set a target: and an action:. Unlike any and all of the examples I found on the web and in the SDK I don't want the message sent to my current object, so I don't want target:self but another object I created elsewhere from another class.
How do I do that? I know I have an object in memory and I know its name but I don't have a pointer to it. For methods there is @selector, is there something like it for objects?
If this helps: In Actionscript I'd write _root.myObjectName.myFunctionName and be set. Is there a way to access objects like this in Objective-C?
Or am I doing it all wrong?
Newbie: Referencing Objects - john42 - Oct 25, 2008 12:09 PM
Hm, anybody? I feel like a complete idiot because it probably is something very easy and stupid.
Newbie: Referencing Objects - Blacktiger - Oct 25, 2008 06:38 PM
I'm having a bit of trouble understanding your situation, thus making it hard to answer your question. Are you programmatically creating your UIBarButtonItem or have you put it in a NIB file? And what do you mean by you know the name of the object? Objects don't have names, they have reference variables which have names.
What you want is to supply a reference to your object for the target.
(I got the UIBarButtonItem creation code off of Apple's forums at http://discussions.apple.com/thread.jspa?threadID=1748715&tstart=0 and just changed the target name. Not that I expect that to be a problem with the NDA fixed anyway.)
Newbie: Referencing Objects - john42 - Oct 25, 2008 09:49 PM
Thank you very much for your answer! I think in spite of my clumsy explanation you got my question right.
In Actionscript (Adobe Flash) every object has an instance name. Thus you can traverse the object hierarchy if you know the names of all objects (starting with _root). I thought I could look up an object by its instance name somehow. But I see this is not possible.
Newbie: Referencing Objects - Blacktiger - Oct 26, 2008 11:18 AM
The typical way to deal with what you are describing is to create your interface in Interface Builder and connect that interface (also in IB) to custom controller objects.
Why do you want to change the target of your UITabBarItem? As far as I know, those are only supposed to change the view displayed in your tabbed interface and while you could certainly make them do other stuff you will likely just confuse your users.