我有一个UIView子类,我从xib文件加载。在我的CustomView.h文件中,我只是忽略了initWithFrame:方法中的CGRect参数:
- (id)initWithFrame:(CGRect)frame {
self = [[[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:nil options:nil] objectAtIndex:0];
return self;
}
现在我的问题是:每当我实例化我的自定义视图时,我应该传递的帧是什么?
例如,我试过这个:
CustomView *cv = [[CustomView alloc] initWithFrame:CGRectZero];
可以假设因为框架是在xib中设置的,所以在这里传递的内容并不重要。但是,这会导致我的自定义视图无法响应用户交互。
答案 0 :(得分:-1)
您可能应该使用initWithCoder
- (id)initWithCoder:(NSCoder*)coder {
self = [super initWithCoder:coder];
if (self){
// Initialization code
}
return self;
}