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

发布于 2024-11-03 06:45:07 字数 1713 浏览 2 评论 0原文

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

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

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  
}

根视图=> d4sViewController =>; d4sMainList1ViewController (从这里我需要删除根视图的所有子视图并返回仅显示根视图。)

In the root view controller I add a subview:

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 I add 2 subviews:

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


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

From this subview, d4sMainList1ViewController, I want to give a logout functionality and go back to root view controller by removing all subview.

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

Rootview => d4sViewController => d4sMainList1ViewController (from here i need to remove all subviews of root and go back to displaying just the root view.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

套路撩心 2024-11-10 06:45:07

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

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

To remove any subview have the send the subview the removeFromSuperView message. See the UIView docs for details.

However, it looks like your stacking views when you don't need to. On a mobile screen a big pile of views is unusable. Look into using UINavigationController to managed a hierarchy of views/viewControllers for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文