Use an integer value as part of a variable name

Nibbie
Posts: 4
Joined: 2009.11
Post: #1
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.
Quote this message in a reply
⌘-R in Chief
Posts: 1,260
Joined: 2002.05
Post: #2
Blink

You call it, by simply… calling it.

Rephrase your question?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
Maybe you want an array?
Quote this message in a reply
Nibbie
Posts: 4
Joined: 2009.11
Post: #4
I only have the number:

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

How could I do this?
Quote this message in a reply
Member
Posts: 144
Joined: 2009.11
Post: #5
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.

Everyone's favourite forum lurker!
https://github.com/NSError
Quote this message in a reply
Nibbie
Posts: 4
Joined: 2009.11
Post: #6
That helps me, thank you very much!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Anybody have an idea what this variable is used for? WhatMeWorry 8 4,401 Mar 1, 2007 10:31 AM
Last Post: unknown
  Converting integer/numeric values to Strings vnvrymdreglage 5 3,655 Oct 23, 2006 07:18 PM
Last Post: vnvrymdreglage
  fgets is only reading part of the line Joseph Duchesne 3 3,151 Feb 10, 2006 01:23 AM
Last Post: Taxxodium
  Mathmatical formula for integer checking Jones 12 5,886 Jan 24, 2006 01:58 AM
Last Post: zKing
  variable frame rate animation in Cocoa Damian 3 3,635 Jul 16, 2003 06:00 PM
Last Post: macboy