Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Must remove from container's subviews when reparenting #1

Open
Artmobile opened this issue Jun 8, 2013 · 9 comments
Open

Must remove from container's subviews when reparenting #1

Artmobile opened this issue Jun 8, 2013 · 9 comments

Comments

@Artmobile
Copy link

I spent several hours trying to understand why a view that was created using your class crashed my application when I called removeFromSuperview on it. Turned out that you do not detach elements from the container when reparenting. To fix, just call [view removeFromSuperview ]; before reparenting.

- (void) loadContentsFromNibNamed:(NSString*)nibName
{
 ...
    // reparent the subviews from the nib file
    for (UIView * view in containerView.subviews){

        // Without this line,  will crash if you attempt calling removeFromSuperview
        [view removeFromSuperview ];

        [self addSubview:view];
    }
}
@n-b
Copy link
Owner

n-b commented Jun 9, 2013

This is quite surprising, I'm pretty sure addSubview effectively removes any link to the previous parent. Are you sure it's not a weird retain/release issue?

@specialunderwear
Copy link

I can confirm this is true

@Artmobile
Copy link
Author

Pretty sure it's not. We are using ARC
On Jun 9, 2013 4:54 PM, "Nicolas Bouilleaud" [email protected]
wrote:

This is quite surprising, I'm pretty sure addSubview effectively removes
any link to the previous parent. Are you sure it's not a weird
retain/release issue?


Reply to this email directly or view it on GitHubhttps://github.com//issues/1#issuecomment-19166451
.

@n-b
Copy link
Owner

n-b commented Sep 20, 2013

@specialunderwear I've reread your original message and I'm even more puzzled. When does the crash happen exactly?

If I understand correctly, the scenario is:

  1. Load a view contents via NibLoading
  2. Later, send - removeFromSuperview to this view.

You see a crash at 2., is this it? Can you try to isolate the crash on a minimal test project?

@Artmobile Artmobile reopened this Sep 21, 2013
@Artmobile
Copy link
Author

Sorry, closed by mistake

@Artmobile
Copy link
Author

I realize that addSubView should move the view from one parent to another. Still, it either did not happen or something else went on. @specialunderwear - are still experiencing the same problem?

@specialunderwear
Copy link

Yes, I fixed it in my fork. Crashes everytime ...

On 21 sep. 2013, at 07:22, IA [email protected] wrote:

I realize that addSubView should move the view from one parent to another. Still, it either did not happen or something else went on. @specialunderwear - are still experiencing the same problem?


Reply to this email directly or view it on GitHub.

@krusek
Copy link

krusek commented Jun 3, 2014

I have the same issue (iOS 6 only) and the same fix works.

@gslomin
Copy link

gslomin commented Jun 20, 2014

I just had to fix this issue myself and was about to send a pull request. Definitely confirmed in iOS6. Works fine in 7 and 8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants