2

I already had many UIImageViews.. I want to make an array of UIImageViews and assign every index with one of the UIImageViews above.. How can I do that with objective c??

2 Answers 2

7

Declare a NSMutableArray

NSMutableArray * imagesArray = [[NSMutableArray alloc] init];

Simply add the Pointers to ImageViews in the Array E.g: imageView1, imageView2

[imagesArray addObjects: imageView1, imageView2, nil];

Don't forget to Release the array if you are not using ARC

Sign up to request clarification or add additional context in comments.

4 Comments

thank you Jamal.. But how can I access each element of the array individually??
I did :).. do u know about accessing the elements??
Whenever you need to assign some image to an imageView simply do: UIImageView * imageView = [imagesArray objectAtIndex:Any index]; imageView.image = [UIImage imagedNamed:@"image.png"];
No such thing as addObjects: . There is an addObject: for one object
2
NSMutableArray * imageViewsArray = [[NSMutableArray alloc] init];
[imageViewsArray addObject:imageView1];
[imageViewsArray addObject:imageView2];

UIImageView * imageView = [imageViewsArray objectAtIndex:0];

or UIImageView * imageView = imageViewsArray[0];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.