Question

J'ai un problème ici. Je crée des étiquettes UIL dynamiquement pour être affichées dans un UIView. Voici le 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];

}
  • Le nombre d'éléments dans le tableau change à chaque fois.
  • Je dois recalculer "flower.flowerQty". et mettez à jour le résultat dans l'étiquette (flowerQuantityLabel).
  • J'ai essayé de charger une référence à chaque flowerQuantityLabel dans un NSMuttableArray (flowersQtyLabels), afin de changer son contenu avec le résultat du recalcul.
  • À la fin du for, le tableau flowersQtyLabels est vide. Je ne sais pas quel est le problème.

J'espère que quelqu'un pourra m'aider.

Était-ce utile?

La solution

Le NSMuttableArray n'a pas été initialisé correctement.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top