问题 EXC_BAD_ACCESS 与“removeFromSuperView”

发布于 2024-11-17 21:31:15 字数 162 浏览 1 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

淡看悲欢离合 2024-11-24 21:31:15

这意味着您调用的对象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.

杀手六號 2024-11-24 21:31:15

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 the NSZombieEnabled flag.

If you want me to write this in French, comment and I'll translate :)

花伊自在美 2024-11-24 21:31:15

我得到这个是因为我在尝试从超级视图中删除它之前已经从视图中删除了所有 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文