0

I have 2 arrays. One is a collection of buttons. The other one should be an array of dictionaries. I am logging the length/size/count of object in the arrays in the console using [arrayListName count]:

2012-07-19 19:56:59.001 ABC[3224:707] lastest_badge_outlet_collection count: 4
2012-07-19 19:56:59.007 ABC[3224:707] badges_array count: 1

ok so when running this loop I want to populate the images with the key value 'name' from each of the dictionaries in existence in the array (that is badges_array). At the moment I have dictionary stored in that array (which is fine). However when I run this through the loop it always populates the third image along

for(int i = 0; i < [lastest_badge_outlet_collection count]; i++){
        UIButton *button = [lastest_badge_outlet_collection objectAtIndex:i];
        if(i < [badges_array count]){
            NSDictionary *badge_d = [badges_array objectAtIndex:i];
            NSString *badge_d_image_string = [badge_d objectForKey:@"image"];
            UIImage *badge_d_image = [UIImage imageNamed: badge_d_image_string];
            [[button imageView] setImage:badge_d_image];
            [[button imageView] setContentMode: UIViewContentModeScaleAspectFit];
            [button setAlpha:1.0f];
        } else {
            [button setAlpha:0.5f];
        }
    }

Theoretically it should be populating the first image. Why is it doing this? How does it decide which order the items are in the outlet collection for example...

Mind boggled.

I tried rewiring them to the collection 1 by 1 by wiring them up in order with no success....

Here is a screenshot.

Thanks!

mindboggled

jimbob
  • 3,288
  • 11
  • 45
  • 70

1 Answers1

1

I don't think there is a way to predict the order of IBOutletCollection.

I guess what you need to do is sort the collection before use it.

You can set tag property for each button and sort them by those number.

Check this answer for more detail.

Community
  • 1
  • 1
Selkie
  • 1,773
  • 1
  • 14
  • 21