从根视图中删除子视图层次结构
在根视图控制器中,我添加一个子视图:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要删除任何子视图,请向子视图发送
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.