我需要从代码中制作一堆按钮并将它们添加到 IBOutletConnection 中。到目前为止,我还无法做到这一点。当我在情节提要中执行此操作时,它工作得很好,但我无法以编程方式将按钮添加到集合中。这是我的代码:
。H
@property (nonatomic, retain) IBOutletCollection(UIButton)NSMutableArray *buttonsArray;
.m
-(void)createButton
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:nil
forControlEvents:UIControlEventTouchDown];
[self writeCloud:button];
button.frame = CGRectMake(-50, 80, 90, 60);
[self.view addSubview:button];
[_buttonsArray addObject:button];
}
我得到的错误是[_buttonsArray addObject:button];
说:
*** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSArrayI addObject:]:无法识别的选择器发送到实例 0x14559050”
谁能指出我做错了什么?