问题 EXC_BAD_ACCESS 与“removeFromSuperView”
我在 xcode 上遇到问题。当我的图像(image1)与image2碰撞时,我想用removefromsuperview删除它,但是当我运行我的应用程序时,出现错误“ EXC_BAD_ACCESS”,我认为这是由于removefromsuperview造成的。我该如何解决这个问题?抱歉我的英语我是法国人:/
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 :/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这意味着您调用的对象removeFromSuperView不存在,或者之前已被释放。
确保您将消息发送到有效的对象。
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
表示您正在使用已释放的对象。使用 Xcode 的分析器 (CMD+A) 查找位置或使用带有NSZombieEnabled
标志的调试器。如果您想让我用法语写这篇文章,请发表评论,我会翻译:)
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 theNSZombieEnabled
flag.If you want me to write this in French, comment and I'll translate :)
我得到这个是因为我在尝试从超级视图中删除它之前已经从视图中删除了所有 CALayers。 self.layer.sublayers = nil 和迭代它们都导致了问题。当以编程方式实例化视图时,效果非常好,但是当我从故事板实例化一个视图时,它显然有指向我不知道的其他层的弱指针。
解决方案?我跟踪了我自己的所有图层,并一次删除了它们,而不是假设 self.layer.sublayers 中的所有图层都是我的。
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.