Como criar NSMutableArray de UILabels?
-
06-07-2019 - |
Pergunta
Eu tenho um problema aqui. Estou criando UILabels dinamicamente a serem exibidos em um UIView. Aqui está o 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];
}
- O número de elementos na matriz muda a cada vez.
- Eu preciso recalcular "flower.flowerQty" e atualizar o resultado na etiqueta (flowerQuantityLabel).
- Eu tentei carregar uma referência para cada flowerQuantityLabel em um NSMuttableArray (flowersQtyLabels), a fim de mudar o seu conteúdo com o resultado do recálculo.
- No final da para, os flowersQtyLabels matriz está vazia. Eu não sei qual é o problema.
Espero que alguém possa me ajudar.
Solução
Eu tinha o NSMuttableArray
não inicializado corretamente.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow