views:

557

answers:

2

hi!!

I have a problem here, Im creating UILabels dynamically to be displayed into a UIView, here is the code:

for (flower in flowerList)
{      

    // Create the Qty label
    CGRect rectQty = CGRectMake(x , y, 25, labelHeight);
    UILabel *flowerQuantityLabel = [[UILabel alloc] initWithFrame:rectQty];
    NSString *fQty = [[NSString alloc] initWithFormat:@"%d", flower.flowerQty];
    [flowerQuantityLabel setText:fQty];
    // Loading refrence into a array  
        // here is the problem 
    [flowersQtyLabels addObject:flowerQuantityLabel];

    // Create the name label
    CGRect rectName = CGRectMake((x+offset) , y, labelWidth, labelHeight);
    UILabel *flowerNameLabel = [[UILabel alloc] initWithFrame:rectName];
    [flowerNameLabel setText:flower.flowerName];

    y = y + 40.0;
    [self.view addSubview:flowerQuantityLabel];
    [self.view addSubview:flowerNameLabel];

}

-The amount of elements in the array is changing every time.

-I need to recalculate "flower.flowerQty" and update the result into the label (flowerQuantityLabel).

-I tried to load a reference to each flowerQuantityLabel into a NSMuttableArray (flowersQtyLabels), in order to change its content with the result of the recalculation.

-at the end of the for i get the array flowersQtyLabels empty :'(, I do not know which is the problem.

I hope some one can help me.

Thanks in advantage Alejandra :)

A: 

Hi StefanB!!

I created the array as a field of my controller:

controller.h

NSMutableArray * flowersQtyLabels; ...

@property (nonatomic, retain) NSMutableArray *flowersQtyLabels;

controller.m

@synthesize flowersQtyLabels;

and i know that is empty because I added a NSLog displaying the [flowersQtyLabels count] and is equals to 0.

thanks for your prompt response :)

Alejandra

Alejandra
A: 

Hi!!

My mistake, I had the NSMuttableArray not initialized properly.

Thanks!!!

Alejandra