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];
And I got
-[CALayer retain]: message sent to deallocated instance
message
[actual removeFromParentViewController];
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.
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)?
UPDATE:
sometimes crash for:
[myactualviewcontroller.view removeFromSuperview];
-[CALayer retain]: message sent to deallocated instance
Why???
and sometimes if I try to remove the main subview from the view controller view, its got the same crash:
[mainView removeFromSuperview]
( mainView is a single UIView, added to the vc.view )
UPDATE2: (well detailed)
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.
subView
is nil? (Even though this shouldn't technically be a problem) – ExclavecontentVc
sounds like a view controller (from the suffix), but you're treating it like a view. Is this intentional? What is that? – ParodycontentVc
is aUIViewController
then it doesn't have asubviews
property. It just has a singleview
. Did you definesubviews
for this view controller? – Parodyfor
returned an object that was NOT aUIView
. Ended up adding aif ([subview isKindOfClass:[UIView class]])
. Not a good solution, but works. Secondly, If you are adding aviewController
's view as a subview and attempt to remove it from superview, try logging something in that VCsviewWillDisappear
/viewDidDisappear
/dealloc
methods to see if they are called. If yes, then check the code over there to see code that might be causing these conflict. – Agitato