remove subview of uiwindow?

Ahamed Aathil picture Ahamed Aathil · Feb 21, 2013 · Viewed 18.5k times · Source

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]); 
}

Answer

Vinayak Kini picture Vinayak Kini · Feb 21, 2013

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];
}