从根视图中删除子视图层次结构

时间:2011-04-25 17:50:46

标签: ios uiviewcontroller subviews

在根视图控制器中,我添加了一个子视图:

d4sViewController = [[D4sViewController alloc] initWithNibName:@"D4sViewController" bundle:nil];

        //----------------------------------------------------------------------
        // Move your sub-view off the screen.
        //----------------------------------------------------------------------
        [self.view addSubview:d4sViewController.view];

        CGRect rect = d4sViewController.view.frame;
        CGPoint origin = CGPointMake(320, 0);
        rect.origin = origin;
        d4sViewController.view.frame = rect;

        //----------------------------------------------------------------------
        // Use a transform to slide it on.
        //----------------------------------------------------------------------
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.5];
        d4sViewController.view.transform = CGAffineTransformMakeTranslation(-320, 0);
        [UIView commitAnimations];

IN D4sViewController我添加了2个子视图:

d4sMainList1ViewController = [[D4sMainList1ViewController alloc] initWithNibName:@"D4sMainList1ViewController" bundle:nil];


        // Move your sub-view off the screen.
        //----------------------------------------------------------------------
        [self.view addSubview:d4sMainList1ViewController.view];

从这个子视图d4sMainList1ViewController,我想提供注销功能,并通过删除所有子视图返回到根视图控制器。

-(IBAction)buttonLogoutClicked:(id)sender
{
 //logout code i need to implement  
}

Rootview => d4sViewController => d4sMainList1ViewController(从这里我需要删除root的所有子视图,然后返回显示根视图。)

1 个答案:

答案 0 :(得分:2)

要删除任何子视图,请向子视图发送removeFromSuperView消息。有关详细信息,请参阅UIView文档。

但是,当您不需要时,它看起来就像是您的堆叠视图。在移动屏幕上,一大堆视图无法使用。查看使用UINavigationController为您管理views / viewControllers的层次结构。