remove subview of uiwindow?

人盡茶涼 提交于 2020-01-02 05:18:11

问题


i want to remove a view from uiwindow,so i nslog in appdelegate method,it says window's subviews count as two NSLog(@" %d",[[self.window subviews] count]); so how can i remove that subviews from window,if i remove that subviews i have tab bar controller to be continued...

- (void) GetUserCompleted

{
    NSLog(@"   %@",[[self.window subviews] objectAtIndex:0]);   
    NSLog(@"   %@",[[self.window subviews] objectAtIndex:1]); 
}

回答1:


You can remove the a single subview using the following code.

[subview_Name removeFromSuperview];

if you want to remove all subviews form the view then use this.

NSArray *subViewArray = [self.window subviews];
for (id obj in subViewArray)
{
    [obj removeFromSuperview];
}



回答2:


Hope the below code will be useful for remove particular view

   Set tag for that remove view

   subview.tag = 1;

   then

   [[[self window] viewWithTag:1] removeFromSuperview];



回答3:


Swift version of @Maddy 's answer:

//create view then add a tag to it. The tag references the view
var myNewView = UIView()
myNewView.tag = 100

//add the  view you just created to the window
window.addSubview(myNewView)

//remove the view you just created from the window. Use the same tag reference
window.viewWithTag(100)?.removeFromSuperview


来源:https://stackoverflow.com/questions/14997175/remove-subview-of-uiwindow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!