问题
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