DrawLayer: inContext - Unrecognized selector sent to instance

I am trying to create a UIViewController that draws a layer, and it works fine if this UIViewController is the main one. However, if I try to initialize it inside another controller, and then add it as a subview of the main controller, this will result in the following error:

-[__NSCFType drawLayer:inContext:]: unrecognized selector sent to instance 0x155140

Here is the relevant code for my custom UIViewController (PDFPageViewController):

- (void)loadDocument:(PDFDocument *)document
{
    self._document = document;

    CGRect pageRect = CGRectIntegral(CGPDFPageGetBoxRect(self._document.page, kCGPDFCropBox));

    pageRect.origin.x = (self.view.frame.size.width / 2) - (pageRect.size.width / 2) - 35;

    CATiledLayer *tiledLayer = [CATiledLayer layer];
    tiledLayer.delegate = self;
    tiledLayer.tileSize = CGSizeMake(1024.0, 1024.0);
    tiledLayer.levelsOfDetail = 1000;
    tiledLayer.levelsOfDetailBias = 1000;
    tiledLayer.frame = pageRect;

    contentView = [[UIView alloc] initWithFrame:pageRect];
    [contentView.layer addSublayer:tiledLayer];

    CGRect viewFrame = self.view.frame;
    viewFrame.origin = CGPointZero;

    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:viewFrame];
    scrollView.delegate = self;
    scrollView.contentSize = pageRect.size;
    scrollView.maximumZoomScale = 1000;
    [scrollView addSubview:contentView];

    [self.view addSubview:scrollView];   

    NSLog(@"%@", self); // Just checking if there nothing overwriting the layer delegate
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return contentView;
}

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
{
    if(self._document) {
        CGContextSetRGBFillColor(ctx, 1.0, 1.0, 1.0, 1.0);
        CGContextFillRect(ctx, CGContextGetClipBoundingBox(ctx));
        CGContextTranslateCTM(ctx, 0.0, layer.bounds.size.height);
        CGContextScaleCTM(ctx, 1.0, -1.0);
        CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform(self._document.page, kCGPDFCropBox, layer.bounds, 0, true));
        CGContextDrawPDFPage(ctx, self._document.page);
    }
}

The drawLayer method exists, and the CALayer delegate itself.

And here is what I call it on my main controller:

pageViewController = [[[PDFPageViewController alloc] initWithNibName:NULL bundle:NULL] autorelease];
[pageViewController loadDocument:self.document];

[self.view addSubview:[pageViewController view]];

? , , , , PDFViewController. , . , ?

+5
1

[ , !]

. NSZombieEnabled? , - ? ARC?

+3

All Articles