I have a problem on xcode. When my image(image1) collide with image2 I want to remove it with removefromsuperview but开发者_开发知识库 when I run my app there is an error " EXC_BAD_ACCESS " , I think it is due to removefromsuperview. How can I solve this ? sorry for my english I'm french :/
This means the object you are calling removeFromSuperView does not exist, or was previously released.
Make sure you are sending the message to a valid object.
EXC_BAD_ACCESS
means that you're using an object after it has been released. Use Xcode's Analyzer (CMD+A) to find where or use the debugger with the NSZombieEnabled
flag.
If you want me to write this in French, comment and I'll translate :)
I got this because I had removed all CALayers from the view before trying to remove it from superview. Both self.layer.sublayers = nil
and iterating over them all caused the problem. Worked perfectly when the view was instantiated programmatically but when I instantiated one from storyboard it apparently had weak pointers to other layers that I didn't know about.
Solution? I kept track of all my own layers and removed them one at a time instead of assuming all layers in self.layer.sublayers
were mine.
精彩评论