我想从uiwindow中删除一个视图,所以我在appdelegate方法中使用nslog,它说窗口的子视图计为两个NSLog(@" %d",[[self.window subviews] count]);
所以如何从窗口中删除该子视图,如果我删除那些子视图我有标签栏控制器继续......
- (void) GetUserCompleted
{
NSLog(@" %@",[[self.window subviews] objectAtIndex:0]);
NSLog(@" %@",[[self.window subviews] objectAtIndex:1]);
}
答案 0 :(得分:14)
您可以使用以下代码删除单个子视图。
[subview_Name removeFromSuperview];
如果要从视图中删除所有子视图,请使用此视图。
NSArray *subViewArray = [self.window subviews];
for (id obj in subViewArray)
{
[obj removeFromSuperview];
}
答案 1 :(得分:9)
希望以下代码对删除特定视图非常有用
Set tag for that remove view
subview.tag = 1;
then
[[[self window] viewWithTag:1] removeFromSuperview];
答案 2 :(得分:5)
@Maddy答案的快速版本:
Public Class Form1
Sub New()
InitializeComponent()
WindowState = FormWindowState.Maximized
Size = New Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height)
Dim p1 As New Panel()
p1.Location = New Point(10, 10)
p1.Size = New Size(ClientSize.Width - 20, ClientSize.Height - 20)
p1.BackColor = Color.Blue
Controls.Add(p1)
End Sub
End Class