我的代码如下,
for (int i=0; i < kNumberOfTitles; ++i) {
UILabel * aLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, i*10, 100, 30)];
[_titles addObject:aLabel];
NSAssert([_titles objectAtIndex:0] != nil, @"wrong 1");
}
NSAssert([_titles objectAtIndex:0] != nil, @"wrong 2");
((UILabel *)[_titles objectAtIndex:0]).text = @"Tel";
((UILabel *)[_titles objectAtIndex:1]).text = @"Add";
for (UILabel* aLabel in _titles) {
[self.view addSubview:aLabel];
}
在第一个 NSAssert 之前,我只是添加了一个新标签然后检索它,我发现它是 nil。有什么问题?