[英]Navigation between subview and superview
在我的程序中,我使用以下代码从主超级视图调用了子视图:[self.viewaddSubview:mysubView.view]; 我想从子视图导航到上一个超级视图,例如“后退功能”。该怎么办? 对于我的项目,我使用xCode 3.0。
您可以使用方法removeFromSuperview和BringSubviewToFront。
听起来您真正想要的是带有“后退”按钮的基本导航栏功能。
查看UINavigationController和这两个功能
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
和
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
在此文档页面上:
是的。您可以发送sendSubviewToBack:
[self.view sendSubviewToBack:mysubView.view];
要么
[mysubView.view removeFromSuperview];
您必须在superView中获取subview的对象并将其存储到数组中,然后根据那里的索引位置将其删除。 如果您仅在超级视图中使用单个子视图,则请遵循以下代码:
NSArray *arr = [SuperView subviews];
NSLog ("objects in arr %@",arr);
[[arr objectAtIndex:0] removeFromSuperview];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.