我有 30 个 UILabel 我希望用作 IBOutlets。但是,当我尝试访问他们的 UILabel 属性时,我收到错误消息,告诉我没有为“id”类型的对象找到属性 x。我对Objective C非常生疏,所以怀疑我做错了什么。我已将所有标签分配给 xib 文件中的 IBCollection。
。H
@interface ViewController : UIViewController
{
IBOutletCollection(UILabel) NSArray *statPanels;
}
@property(retain) IBOutletCollection(UILabel) NSArray *statPanels;
@end
.m
@interface ViewController ()
@end
@implementation ViewController
@synthesize statPanels;
- (void)viewDidLoad
{
[super viewDidLoad];
statPanels = [[NSArray alloc] initWithObjects:[UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], [UILabel alloc], nil ];
[statPanels objectAtIndex:3].hidden = YES;
}