¿Cómo crear NSMutableArray de UILabels?
-
06-07-2019 - |
Pregunta
Tengo un problema aquí. Estoy creando UILabels dinámicamente para mostrarlos en una UIView. Aquí está el código:
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];
}
- El número de elementos en la matriz cambia cada vez.
- Necesito volver a calcular " flower.flowerQty " y actualice el resultado en la etiqueta (flowerQuantityLabel).
- Intenté cargar una referencia a cada flowerQuantityLabel en un NSMuttableArray (flowersQtyLabels), para cambiar su contenido con el resultado del recálculo.
- Al final de for, la matriz flowersQtyLabels está vacía. No sé cuál es el problema.
Espero que alguien pueda ayudarme.
Solución
Tenía el NSMuttableArray
no inicializado correctamente.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow