SimonRH
SimonRH

Reputation: 1469

How do I load objects and set properties dynamically?

I have several instances of a UIImageView that I want to manage dynamically. I want to load each into a mutable array, then set the animationImages property of each instance. My question: How can I load the UIImageViews into the mutable array and then how can I set the properties dynamically? Here's how I create the animation object:

for (int i = 1; i <= 20; i++) {[myAnimation addObject:[UIImage imageNamed: [NSString stringWithFormat:@"frame-%i.png", i]]]; }

Here's how I add the objects (not dynamic):

NSMutableArray *collection = [[NSMutableArray alloc]initWithObjects:imageView1,imageView2,...nil];

I'm not sure how to set the properties. I think it should be similar to the following:

for (id xxx in collection) {
    xxx.animationImages=someAnimation;      
}

Upvotes: 0

Views: 192

Answers (2)

The iOSDev
The iOSDev

Reputation: 5267

just add UIImageView *imageView = (UIImageView *) xxx; before the line in the for loop you used like this

for (id xxx in collection) {
// Here add the line    
xxx.animationImages=someAnimation;      
}

Upvotes: 1

heckman
heckman

Reputation: 499

If you are wanting to use the fast enum for loop style, you need to use:

for (UIImageView * xxx in collection) {
    xxx.animationImages=someAnimation;      
}

Based on what your doing though, it looks like you should consider adding these to some containing view, and lay them out from the appropriate layoutSubviews: call within the managing view. Where you would do something like (from the view containing your image views):

for (UIImageView * view in [self subviews]) {
    // move the image view around as needed.
}

Will provide additional details if this is inline with what you are attempting to accomplish, but it is still unclear as to what you are attempting to 'manage' with this code.

Upvotes: 0

Related Questions