iDevGames Forums
Use an integer value as part of a variable name - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Use an integer value as part of a variable name (/thread-585.html)



Use an integer value as part of a variable name - PHANTOMIAS - Nov 18, 2009 09:19 AM

Hello!

I have many UIImageView´s on my MainView named imageView1, imageView2, ...
I can detect which imageView is tapped because of the coordinates.

So I have the number, for example 3, but how can I call something like
Code:
imageView3.image = [UIImage imageNamed:@"test.png"];

Do you have an idea?

Thanks & Regards.


Use an integer value as part of a variable name - SethWillits - Nov 18, 2009 12:31 PM

Blink

You call it, by simply… calling it.

Rephrase your question?


Use an integer value as part of a variable name - OneSadCookie - Nov 18, 2009 12:49 PM

Maybe you want an array?


Use an integer value as part of a variable name - PHANTOMIAS - Nov 18, 2009 04:56 PM

I only have the number:

...
int FIELD = [testController getField:point];
-> now I want to call imageViewFIELD.image = ...

How could I do this?


Use an integer value as part of a variable name - cmiller - Nov 18, 2009 10:56 PM

Yeah you want an array. What you're trying to do isn't possible, though by using an array you can achieve the same result.

Code:
NSArray * imageViews = ...;
int FIELD = [testController getFieldPoint];
[[imageViews objectAtIndex:FIELD] setImage:...];

Look at the NSArray [developer.apple.com] class reference to get yourself started.


Use an integer value as part of a variable name - PHANTOMIAS - Dec 8, 2009 09:24 AM

That helps me, thank you very much!