Why does this CALayer not display an image?

I assume that this code is from your view controller and that its view has been properly constructed before this (otherwise, you'll be sending messages to nil). Also, I assume by addedObject above, you mean selectedImage One thing that jumps out at me is that layerBack display should be replaced with layerBack setNeedsDisplay From the CALayer documentation in regards to display: You should not call this method directly There's more on setting the content of layers like this in the Providing Layer Content section of the Core Animation Programming Guide.

I assume that this code is from your view controller and that its view has been properly constructed before this (otherwise, you'll be sending messages to nil). Also, I assume by addedObject above, you mean selectedImage. One thing that jumps out at me is that layerBack display; should be replaced with layerBack setNeedsDisplay; From the CALayer documentation, in regards to -display: You should not call this method directly.

There's more on setting the content of layers like this in the "Providing Layer Content" section of the Core Animation Programming Guide.

That's it! Thankss! – Digital Robot Sep 10 '09 at 20:24 David Duncan answered this on cocoa-dev maillist: By default this will obliterate the contents that you have just set.

Calling -setNeedsDisplay or -display will cause the layer to generate content and set the contents property to the result of that operation. If you set the contents property manually, you should never call -setNeedsDisplay or -display on that layer or the content you set will be lost. You can avoid this by implementing some delegate methods or subclassing a CALayer, but it is generally easier to avoid the issue entirely by maintaining control over the CALayer when doing this.

– Johan Kool Dec 23 '09 at 0:52.

Well first of all I think you have to cast the CGImage to an id. LayerBack. Contents = (id)selectedImage.

CGImage; And secondly, I think you have to add the layer to the views content layer self.view. Layer addSublayer:layerBack; But I have always made use of my custom UIViews class's + (Class)layerClass; to generate custom layers which layout their own sublayers, but maybe that's just me.

Thanks. I did both changes and the layer is still not showing. If I may ask, can you, by any chance, kindly send me this class you've created?

If you can, please mail it to "utugau-->at.

From what I see, you get an image, but then add in an entirely different, unrelated image, possibly a blank one, to the layer. Are you paying attention to messages Xcode is providing you?

That addObject was a typo when I copied the code to SO... as I changed a few variables when typing the code here to clarify...thanks for the help. – Digital Robot Sep 10 '09 at 20:24.

Bridge it: layerBack. Contents = (__bridge id)selectedImage.CGImage.

This Quartz stuff is driving me crazy! Yes, the image is there and is working, but all I see after this code is a blank screen.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions