0

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?

2
  • What error u r getting? Replacing the image thru code will not be reflected in the nib file. Commented Jul 27, 2011 at 4:53
  • Request for member 'image' in something not a structure or union Commented Jul 27, 2011 at 5:01

2 Answers 2

1

QueueOverflow's solution is correct. In addition to that, u can also do like,

((UIImageView *)[imageArray objectAtIndex:0]).image = [UIImage imageNamed:@"someimage.png"];
Sign up to request clarification or add additional context in comments.

2 Comments

I have also changed the imageWithName to imageNamed. If not required, u can continue with ur method.
Thank you. This makes much more sense to me.
1

Try this

UIImageView *selectedImageView = (UIImageView *)[imageArray objectAtIndex:0];
selectedImageView.image = [UIImage imageWithName:@"someimage.png"];

2 Comments

No cigar, although I was trying something similar to this earlier. Is there no way to directly access an array member's properties? If that makes any sense x_x
This is a directway.. And if you get this error "Request for member 'image' in something not a structure or union" then the object in that array is not a imageView..

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.