0

我有 4ViewControllers作为startViewController初始视图控制器。这包含我的介绍。完成后,它将[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];

ImportantViewController即使我转到其他视图,我想要的是使其成为父视图或 mainVIew。我需要的是ImportantViewController当我去的时候出现C1ViewController或者menuViewController它不会被释放,或者它的内容仍然会被保留。

是否可以?如何?

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

顺便说一句,我使用故事板。

4

2 回答 2

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

您可以对第二个视图或任意数量的视图执行相同操作。我发现这比展示视图控制器更好。您还可以将核心动画添加到子视图并创建一个漂亮的 UI。

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

于 2012-07-01T15:18:39.317 回答
0

制作ImportantViewControllera 的根视图UINavigationController,您将呈现 aUINavigationController而不是 ImportantViewController,

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

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

现在在重要视图控制器中展示新的视图控制器,您将执行以下操作

[self.navigationController pushViewController:yourC1ViewController animated:YES];
于 2012-07-01T15:21:07.817 回答