Domanda

Ho un problema qui. Sto creando UILabels in modo dinamico per essere visualizzato in una UIView. Ecco il codice:

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];

}
  • Il numero di elementi nell'array cambia ogni volta.
  • Devo ricalcolare " flower.flowerQty " e aggiorna il risultato nell'etichetta (flowerQuantityLabel).
  • Ho provato a caricare un riferimento a ciascun flowerQuantityLabel in un NSMuttableArray (flowersQtyLabels), al fine di modificarne il contenuto con il risultato del ricalcolo.
  • Alla fine di for, l'array flowersQtyLabels è vuoto. Non so quale sia il problema.

Spero che qualcuno mi possa aiutare.

È stato utile?

Soluzione

Il NSMuttableArray non è stato inizializzato correttamente.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top