[英]How to remove subview from Superview?
I have taken one subView of type UIView on the top of UIViewController. 我在UIViewController的顶部拍摄了一个UIView类型的subView。 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.
我已经使用了[subView removeFromSuperview]方法。 But it is not working.
但这是行不通的。
Try out the method inside the AppDelegate. 试用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.
如果您已将rootViewController.view作为窗口的子视图加载,请尝试再次将其卸载,您应该会看到一个白屏。
[self.window addSubview:rootViewController.view];
[rootViewController.view removeFromSuperview];
Also, insert this line before you removeFromSuperview in your code: 另外,在代码中removeFromSuperview之前插入以下行:
NSLog(@"%@",[rootViewController.view superview]);
Replace rootViewController.view with your view. 用您的视图替换rootViewController.view。 If the log reads (null), it means you have incorrectly assigned your view as a subview.
如果日志显示为(空),则表示您已错误地将视图分配为子视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.