从xib调用自定义视图时调用xib会导致崩溃

时间:2012-06-20 05:40:05

标签: objective-c ios exc-bad-access runtime-error

在一个.xib文件中,我添加一个视图并将其类修改为我的CustomViewClass。在该类中,我有创建.xib时调用的重写方法:

- (id)initWithCoder:(NSCoder *)aDecoder{
if(self == [super initWithCoder:aDecoder]){
    //Load  the xib
    NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"SliderVW" owner:nil options:Nil];
    self = [array objectAtIndex:0];
}
return self;
}

此方法调用一个xib将自我视图分配给CustomViewClass,但出了点问题;我在行

上获得了EXC_BAD_ACCESS
NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"SliderVW" owner:nil options:Nil];

但我无法理解为什么。

1 个答案:

答案 0 :(得分:0)

使用以下内容查看是否有效:

NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"SliderVW" owner:self options:nil];

已将所有人的参数“nil”更改为“self”。

相关问题