开发者

problem EXC_BAD_ACCESS with "removeFromSuperView

开发者 https://www.devze.com 2023-03-16 23:34 出处:网络
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 thin

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消