嘿我想在运行时创建标签并删除它们。首先,我希望我的程序在我的滚动视图中间的视图已加载时创建标签。 到目前为止,我的viewDidLoad看起来像这样:
- (void)viewDidLoad {
[super viewDidLoad];
inputArray = [[NSMutableArray alloc] initWithObjects:@(0), nil];
UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake(
(_scrollViewForLabels.frame.origin.x + (_scrollViewForLabels.frame.size.width / 2)),
(_scrollViewForLabels.frame.origin.y + (_scrollViewForLabels.frame.size.height / 2)),
0,0)];
label.text = [[inputArray lastObject] stringValue];
label.textColor = [UIColor whiteColor];
[labelArray addObject:(label)];
[_scrollViewForLabels addSubview:label];
但我看不到应该在任何地方显示的0。它可能在哪里?
答案 0 :(得分:0)
在尝试添加标签数组之前,您需要初始化标签数组...
- (void)viewDidLoad {
[super viewDidLoad];
inputArray = [[NSMutableArray alloc] initWithObjects:@(0), nil];
// add this line
labelArray = [NSMutableArray array];
// the rest of your setup...
}