Accessing/setting UIImageView from array
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 syn开发者_Go百科thesize 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?
QueueOverflow's solution is correct. In addition to that, u can also do like,
((UIImageView *)[imageArray objectAtIndex:0]).image = [UIImage imageNamed:@"someimage.png"];
Try this
UIImageView *selectedImageView = (UIImageView *)[imageArray objectAtIndex:0];
selectedImageView.image = [UIImage imageWithName:@"someimage.png"];
精彩评论