문제

여기에 문제가 있습니다. UIVIEW에 동적으로 UILABELS를 만들고 있습니다. 코드는 다음과 같습니다.

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