سؤال

عندي مشكلة هنا.أقوم بإنشاء 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).
  • لقد حاولت تحميل مرجع لكل زهرةQuantityLabel في NSMuttableArray (flowersQtyLabels)، من أجل تغيير محتواها مع نتيجة إعادة الحساب.
  • في نهاية for، تكون مصفوفة FlowerQtyLabels فارغة.لا أعرف ما هي المشكلة.

آمل أن يتمكن أحد من مساعدتي.

هل كانت مفيدة؟

المحلول

كان لدى ال NSMuttableArray لم تتم التهيئة بشكل صحيح.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top