Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing a variable in a statement to reference the image stored in a UIImageView
    text
    copied!<p>UPDATED Scroll down to see the question re-asked more clearly.... If I had the name of a particular UIImageView (IBOutlet) stored in a variable, how can I use it to change the image that is displayed. I tried this, but it does not work.</p> <p>I'm still new to iphone programming, so any help would be appreciated.</p> <pre><code>NSString *TmpImage = @"0.png"; NSString *Tst = @"si1_1_2"; TmpImage = @"1.png"; UIImage *sampleimage = [[UIImage imageNamed:TmpImage] retain]; ((UIImageView *) (Tst)).image = sampleimage; // This is the line in question [sampleimage release]; </code></pre> <p>RESTATED:</p> <p>I have a bunch of images on the screen.... UIImageView *s1, *s2 ,*s3 etc up to *s10 <BR> Now suppose I want to update the image each displays to the same image.<BR> Rather than doing<BR> s1.image = sampleimage;<BR> s2.image = sampleimage;<BR> :<BR> s10.image = sampleimage;<BR></p> <p>How could i write a for loop to go from 1 to 10 and then use the loop var as part of the line that updates the image.<BR> Something like this.<BR> for ( i = 1; i &lt;- 10; ++i )<BR> s(i).image = sample; // I know that does not work<BR></p> <p><BR> Basic question is how do I incorporate the variable as part of the statement to access the image? Don't get hung up on my example. The main question is how to use a variable as part of the access to some element/object. <BR><BR></p> <p>Bottom Line... If I can build the name of a UIImageView into a NSString object, How can I then use that NSString object to manipulate the UIImageView.</p> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload