iOS 7.1 removeFromSuperview崩溃 [英] iOS 7.1 removeFromSuperview crash

查看:670
本文介绍了iOS 7.1 removeFromSuperview崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iOS 7.1 出来之前,我的应用没有任何崩溃。现在在任何 removeFromSuperview 方法上,崩溃。例如:我有视图控制器,当我想删除一个视图控制器时,我删除它的所有子视图,然后从堆栈中删除(堆栈:我在此存储视图控制器,用于加载新内容,并加载以前的内容):

My app didn't have any crash until iOS 7.1 came out. Now on any removeFromSuperview method, crash. For example: I got view controllers, and when I want to remove a view controller, I remove all of its subviews, and then remove from the stack (stack: I'm storing view controllers in this, for load new contents, and load previous contents):

    for (UIView *subView in [contentVc subviews])
         [subView removeFromSuperview];

我得到了


- [CALayer retain]:发送到解除分配实例的消息

-[CALayer retain]: message sent to deallocated instance

消息

[actual removeFromParentViewController];

是删除它的好方法吗?它会释放整个视图控制器及其子视图吗?因为而不是removeFromSuperview,我的应用程序不会崩溃。我不明白在iOS 7.1中有什么变化。

is a good way to remove it? And will it release the whole view controller and its subviews? Because instead of removeFromSuperview, my app doesn't crash. I don't understand what have been changed in iOS 7.1.

如何删除 viewController 没有 removeFromSuperview ,并且没有删除我的 ViewController (如果我只想添加新的子视图,并删除当前内容)?

And how can I remove all subviews in a viewController without removeFromSuperview, and without remove my ViewController (if I just want to add new subviews, and remove the currently content)?

更新:

有时崩溃:

[myactualviewcontroller.view removeFromSuperview];




- [CALayer retain]:发送到解除分配实例的消息

-[CALayer retain]: message sent to deallocated instance

为什么???

有时如果我尝试删除主子视图视图控制器视图,它同样崩溃:

and sometimes if I try to remove the main subview from the view controller view, its got the same crash:

[mainView removeFromSuperview] (mainView是单个UIView,添加到vc.view)

[mainView removeFromSuperview] ( mainView is a single UIView, added to the vc.view )

UPDATE2 :(详细信息)

所以,我有一个容器视图。我正在向此容器添加 UIViewController.view 。我正在将一个视图作为子视图添加到 UIViewController.view 。这个视图不是本地uiview,我的意思是,它声明为实现{UIView * mainView} 。当我的UIViewController将被解除分配时,在其中 - (void)dealloc {[mainView removeFromSuperview]; [mainView发布] [super dealloc];}
在mainView removeFromSuperview我的应用程序崩溃。

so, I've got a container view. I'm adding a UIViewController.view to this container. And I'm adding a view as a subview to UIViewController.view. This view is not a local uiview, I mean, its declared as implementation{ UIView* mainView } .When my UIViewController will be deallocate, in its - (void) dealloc { [mainView removeFromSuperview]; [mainView release] [super dealloc];} At the mainView removeFromSuperview my app crash.

推荐答案

您的程序崩溃了,因为您不止一次发布了某些内容。这部分是显而易见的。

Your program is crashing because you are releasing something more than once. That part is obvious.

找到它的第一步是在调试器中启用僵尸检测。 ( Project-> Schemes-> Edit Scheme-> Diagnostics-> Enable Zombie Objects )。这里的目标是让您的程序更快崩溃。一旦您尝试访问已释放的实例,这将使您进入调试器。有时这会指向正确的方向,有时不是,但最好尽可能地将其检测到尽可能接近问题的位置。

The first step in finding it is to enable zombie detection in the debugger. (Project->Schemes->Edit Scheme->Diagnostics->Enable Zombie Objects). The goal here is to make your program crash sooner. This will drop you into the debugger as soon as you try to access a deallocated instance. Sometimes this will point you in the right direction, sometimes not, but it's always better to detect it as close to where the problem is as possible.

下一步是使用Zombies乐器。此工具将为您提供比上一步更多的信息,但使用起来更复杂(这就是为什么我将其设为步骤2而不是步骤1)。 Zombies工具将跟踪您的所有分配和发布,并检测您何时尝试访问僵尸对象。

The next step is to use the Zombies instrument. This tool will give you more information than the previous step, but it's more complex to use (which is why I made it step 2 instead of step 1). The Zombies tool will keep track of all your allocations and releases, and detect when you try to access a zombie object.

最后一种方法是开始注释掉代码。首先注释掉程序在创建视图控制器(崩溃的控制器)和释放视图控制器之间所做的一切。然后运行程序并执行任何操作以使其显示错误的视图控制器。显然,它不会做任何事情,因为它现在只是一个空的视图控制器,但它不应该崩溃)。然后开始取消注释代码块,一次一点,并在每次迭代之间继续运行它。这是一个重复的过程,如果您的视图控制器代码很大且很复杂,则可能会很繁琐。但我的想法是不断添加你的代码,直到你添加一些东西然后崩溃 - 然后你就知道你已经找到导致问题的代码片段了。你必须在这里有创意,并仔细选择如何重新编写代码 - 如果你的程序有一个很好的模块化设计,你应该能够毫不费力地做到这一点。意大利面条代码很难做到这一点,但它可能会给你一个很好的机会来重构你的代码。通过这个过程,您将缩小问题的范围并最终通过消除过程找到错误。

The last resort is to start commenting out code. First comment out everything your program does between the time you create the view controller (the one that crashes) and when you release it. Then run the program and do whatever you need to do to make it display the bad view controller. It won't do anything, obviously, because it's just an empty view controller now, but it should not crash). Then start uncommenting blocks of code, a little bit at a time, and keep running it in between each iteration. This is a repetitive process, and can be tedious if your view controller code is large and complex. But the idea is to keep adding your code back in little by little until you add something back and it crashes - then you know you've found the piece of code that's causing the problem. You have to be creative here and choose carefully how you put your code back in - if your program has a nice modular design, you should be able to do this without much trouble. Spaghetti code will be difficult to do this with, but it might give you a good opportunity to restructure your code while you're at it. By going through this process, you'll narrow down the problem and eventually find the bug by process of elimination.

这篇关于iOS 7.1 removeFromSuperview崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆