ViewController导航

时间:2012-07-01 15:08:24

标签: iphone ios xcode

我有4 ViewControllersstartViewController作为初始视图控制器。这包含我的介绍。完成后,它会[self presentViewController:vc animated:YES completion:NULL];进入我的menuViewController


startViewController ------> menuViewController ------> C1ViewController
                                          \
                                           \ ------> ImportantViewController

在我的menuViewController按钮中,两个ViewController的按钮就像上图所示。我还在视图中将它们与[self presentViewController:vc animated:YES completion:NULL];一起展示给了menuViewController

我想要的是使[self dismissModalViewControllerAnimated:YES];与父视图或mainVIew类似,即使我转到其他视图。我需要的是,当ImportantViewControllerImportantViewController转到C1ViewControllermenuViewController时,它会被解除分配,或者其中的内容仍会被保留。

有可能吗?怎么样?

我对父视图和子视图控制器的了解不多,所以我不知道在我的问题中要实现什么。谢谢。

BTW,我正在使用故事板。

2 个答案:

答案 0 :(得分:0)

我不是100%想要做什么,但是如果你使用ARC,将ImportantViewController设置为__strong它将保留给你。为什么不通过在ImprotantViewController.m中以编程方式创建所需的视图控制器来使ImportantViewController成为父项?

// ImportantViewController.m
// non ARC
FirstChildViewController *firstChild = [[FirstChildViewController alloc] initWithNib@"FirstChildViewController" bundle:nil];

//set firstChild.view position here if needed. e.g. .center = CGPointMake(x,y);

//now add firstChild to the parent
[self addSubview:firstChild];
[firstChild release];

您可以对第二个视图或任意数量的视图执行相同操作。我觉得这比呈现视图控制器更好。您还可以将Core Animations添加到子视图中,并创建一个漂亮的UI。

这回答了你的问题吗?也许我没有得到你想要的。 :)

答案 1 :(得分:0)

ImportantViewController设为UINavigationController的根视图,您将显示UINavigationController而不是ImportantViewController,

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:YourImportantViewControllerOBject];

//insted of presentModalViewControlle with YourImportantViewControllerOBject you do
[self presentModalViewController:navigationController animated:YES];

现在在ImportantViewController中呈现新的视图控制器,您将执行以下操作

[self.navigationController pushViewController:yourC1ViewController animated:YES];
相关问题