简体   繁体   中英

How to remove subview from Superview?

I have taken one subView of type UIView on the top of UIViewController. I want to remove it and again load it after clicking on button. But I am unable to remove it. I have used [subView removeFromSuperview] method. But it is not working.

Try out the method inside the AppDelegate. If you have loaded the rootViewController.view as a subview to your window, try to unload it again, you should see a white screen.

[self.window addSubview:rootViewController.view];
[rootViewController.view removeFromSuperview];

Also, insert this line before you removeFromSuperview in your code:

NSLog(@"%@",[rootViewController.view superview]);

Replace rootViewController.view with your view. If the log reads (null), it means you have incorrectly assigned your view as a subview.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM