子视图和superview之间的导航

时间:2011-10-07 04:16:36

标签: iphone objective-c ios

在我的程序中,我使用以下代码从主superview调用subview:[self.viewaddSubview:mysubView.view];我想从子视图导航到之前的超级视图,如'后退功能'。如何做到这一点?对于我的项目,我使用xCode 3.0。

4 个答案:

答案 0 :(得分:0)

您可以使用方法removeFromSuperview和bringSubviewToFront。

答案 1 :(得分:0)

听起来你真正想要的是具有“后退”按钮的基本导航栏功能。

查看UINavigationController和这两个函数

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated

- (UIViewController *)popViewControllerAnimated:(BOOL)animated

在此文档页面:

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UINavigationController_Class/Reference/Reference.html

答案 2 :(得分:0)

是的。你可以, sendSubviewToBack:

[self.view sendSubviewToBack:mysubView.view];

[mysubView.view removeFromSuperview];

答案 3 :(得分:0)

您必须在superView中获取子视图的对象并将它们存储到数组中,然后根据索引位置将其删除。如果您在超级视图中仅使用单个子视图,请遵循以下代码:

NSArray *arr = [SuperView subviews];

NSLog ("objects in arr %@",arr);

[[arr objectAtIndex:0] removeFromSuperview];
相关问题