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
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
4 Comments
nouf
thank you Jamal.. But how can I access each element of the array individually??
nouf
I did :).. do u know about accessing the elements??
Jamal Zafar
Whenever you need to assign some image to an imageView simply do: UIImageView * imageView = [imagesArray objectAtIndex:Any index]; imageView.image = [UIImage imagedNamed:@"image.png"];
ekashking
No such thing as
addObjects: . There is an addObject: for one object