Reputation: 141
Having issues with this, I'm certain that I'm not grasping something.
Let's say I've created properties for three image views and linked those views to three views in Interface Builder. I synthesize them, link them all in IB (double checked). I've also created a property for a NSMutableArray and synthesized it.
When the view loads (viewdidload), I put all of the aforementioned image views into the array. For example:
[imageArray initWithObjects: img1, img2, img3, nil];
How do I directly access/set/change/whatever the views directly from the array?
For instance, if I wanted to change what img1 is displaying, I've been trying things like:
[imageArray objectAtIndex:0].image = [UIImage imageWithName:@"someimage.png"];
But it gives me an error. If I replace img1 in the array, will it display in IB?
Upvotes: 0
Views: 283
Reputation: 17478
QueueOverflow's solution is correct. In addition to that, u can also do like,
((UIImageView *)[imageArray objectAtIndex:0]).image = [UIImage imageNamed:@"someimage.png"];
Upvotes: 1
Reputation: 16553
Try this
UIImageView *selectedImageView = (UIImageView *)[imageArray objectAtIndex:0];
selectedImageView.image = [UIImage imageWithName:@"someimage.png"];
Upvotes: 1