質問

ここに問題があります。 UILabelsを動的に作成して、UIViewに表示しています。コードは次のとおりです。

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

}
  • 配列内の要素の数は毎回変わります。
  • 「flower.flowerQty」を再計算する必要があります。結果をラベル(flowerQuantityLabel)に更新します。
  • 再計算の結果で内容を変更するために、各flowerQuantityLabelへの参照をNSMuttableArray(flowersQtyLabels)にロードしようとしました。
  • forの最後では、flowersQtyLabels配列は空です。問題が何なのかわかりません。

誰かが私を助けてくれることを願っています。

役に立ちましたか?

解決

NSMuttableArray が正しく初期化されていませんでした。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top