Reputation: 536
I have some UIImageView
s in an array and want to loop through them to set an image, but I don't know how.
If I have one ImageView, imgv
, then I do this:
self.imgv.image =
But how do I behave with many UIImageViews in a loop? I can't do the following:
for(int i = 0; i < [imageViewArray count]; i++)
{
self.i.image =
}
Upvotes: 1
Views: 1114
Reputation: 13222
If you need to set same image to all image views in the array then simply use,
[imageViewArray makeObjectsPerformSelector:@selector(setImage:) withObject:image];
If you need to set different images then you have to loop through the array like most of the answer have mentioned.
Hope that helps!
Upvotes: 1
Reputation: 10424
Try this
for(UIImageView *imgVw in imageViewArray)
{
imgVw.image = ...;
}
for - in is used to iterate through all the element of an array.
Upvotes: 0
Reputation: 119021
You use the index in the loop to get an item out of the array:
for(int i = 0; i < [imageViewArray count]; i++)
{
UIImageView *imageView = imageViewArray[i];
imageView.image = ...;
}
or, you use a for in
loop:
for (UIImageView *imageView in imageViewArray)
{
imageView.image = ...;
}
Upvotes: 5
Reputation: 2064
for(int i = 0; i < [imageViewArray count]; i++)
{
UIImageView *tempImageView = [imageViewArray objectAtIndex:i];
tempImageView.image=image;
}
Upvotes: 3
Reputation: 960
for(int i = 0; i < [imageViewArray count]; i++)
{
[imageViewArray[i] setImage:image];
}
Upvotes: 1