如何修复"实例变量,而自我'"

时间:2014-07-24 17:20:55

标签: objective-c

如何解决此分析问题:

enter image description here

CODE

if(![super initWithFrame:CGRectZero]){
    return nil;
}

firstOfPrev = -1;
marks = markArray;
monthDate = date;
startOnSunday = sunday;

1 个答案:

答案 0 :(得分:1)

您收到错误是因为您从未将超级初始化程序调用的结果分配给self。我相信这就是你想要的:

- (instancetype)initWithFrame:(CGRect)frame
{
    if (!(self = [super initWithFrame:frame])) {
        return nil;
    }

    // do stuff

    return self;
}

但是,如果你写出这样的初始化器,这可能会更清楚:

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];

    if (self) {
        // do stuff
    }

    return self;
}