我这里有问题。我正在动态创建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];
}
我希望有人可以帮助我。
答案 0 :(得分:0)
我将数组创建为控制器的字段:
controller.h
NSMutableArray * flowersQtyLabels; ......
@property(nonatomic,retain)NSMutableArray * flowersQtyLabels;
controller.m
@synthesize flowersQtyLabels;
我知道这是空的,因为我添加了一个显示[flowersQtyLabels计数]的NSLog,并且等于0.
感谢您的快速回复:)
亚历杭
答案 1 :(得分:0)
我的错误,我没有正确初始化NSMuttableArray。
感谢!!!