【问题标题】:Removing subview hierarchy from root view从根视图中删除子视图层次结构
【发布时间】:2011-04-25 17:50:46
【问题描述】:

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

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(从这里我需要删除根的所有子视图并返回只显示根视图。)

【问题讨论】:

    标签: ios uiviewcontroller subviews


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-11
      • 1970-01-01
      • 1970-01-01
      • 2022-10-21
      • 1970-01-01
      相关资源
      最近更新 更多