Переменная экземпляра, используемая в то время как 'self' не установлена ​​на результат - PullRequest
4 голосов
/ 24 ноября 2011

Я работаю с SGAREnvioroment, и я получаю следующую ошибку:

Переменная экземпляра, используемая, когда для 'self' не задан результат '[(super или self) init ...] '

В этом фрагменте кода:

@interface SG3DOverlayView (Private)

- (id) initGLES;
- (void) drawView;
- (BOOL) createFramebuffer;
- (void) destroyFramebuffer;

- (void) clearTouches;

@end

@implementation SG3DOverlayView

+ (Class) layerClass
{
    return [CAEAGLLayer class];
}

-(id) initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame]) {
        self = [self initGLES];
    }

    return self;
}

-(id) initGLES
{
    self.multipleTouchEnabled = YES;
    self.exclusiveTouch = YES;

    CAEAGLLayer *eaglLayer = (CAEAGLLayer*) self.layer;

    eaglLayer.opaque = YES;
    eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                                    [NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking,
                                    kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat,
                                    nil];

    context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
    if(!context || ![EAGLContext setCurrentContext:context] || ![self createFramebuffer]) {
        [self release];
        return nil;
    }

    self.backgroundColor = [UIColor clearColor];

    mainSubview = [[UIView alloc] initWithFrame:self.frame];
    mainSubview.backgroundColor = [UIColor clearColor];

    animationInterval = 1.0;
    pinchTimer = nil;
    dragging = NO;
    currentSphereRadius = 0.0;

    [self clearTouches];

    return self;
}

Я получаю здесь «ошибку»:

if(!context || ![EAGLContext setCurrentContext:context] || ![self createFramebuffer]) {

Но, как вы можете видеть, self настроен на -(id) initWithFrame:(CGRect)frame, а -(id) initGLES является личным, поэтому он всегда вызывается с -(id) initWithFrame:(CGRect)frame.

Итак, могу ли я что-то сделать, чтобы это исправить?

Ответы [ 2 ]

9 голосов
/ 24 ноября 2011

Не ставьте префикс имени вашей функции перед init - анализатор предполагает, что это инициализатор, и в этом случае это не так.

Кроме того, функция не должна возвращать self, если это не такинициализирую это.Сделайте его недействительным.

...