以编程方式创建一个带有两个使用导航控制器的 uiviewcontroller 的 splitviewcontroller

发布于 2024-10-27 17:01:23 字数 559 浏览 1 评论 0原文

我想以编程方式创建一个 UISplitViewController ,并将两个 UIViewController 子类作为其主控制器和详细控制器(左窗格和右窗格),我用它们来处理各种事情,例如选择单元格时的处理等。

我的问题是,我不确定如何在这些自定义主控制器和详细控制器中创建导航控制器并将它们连接到 splitview 控制器。目前,我像这样添加我的控制器:

mSplitViewController.viewControllers = [NSArray 
    arrayWithObjects:mSplitMasterController,mSplitDetailController, nil];

并且在每个自定义控制器中我创建了一个容器 UIView,我可以在其中组装我的子视图。我不确定如何将导航控制器添加到其中。我是否需要在自定义控制器的 loadView 中基本上执行类似的操作?

[self.view addSubview:mNavigationController.view];

在构建导航控制器将管理的控制器(及其视图)之后?

I would like to create a UISplitViewController programmatically and have as its master and detail controller (the left and right pane), two UIViewController subclasses which I use to handle various things like processing when cells are selected and so forth.

My problem is that I'm not certain how to create navigation controllers within these custom master and detail controllers and hook them up to the splitview controller. Currently, I add my controllers like this:

mSplitViewController.viewControllers = [NSArray 
    arrayWithObjects:mSplitMasterController,mSplitDetailController, nil];

and I within each custom controller I have a container UIView created on which I can assemble my subviews. I'm not sure how I add the navigation controllers to these. Do I need to basically do something like this within my custom controllers' loadView?

[self.view addSubview:mNavigationController.view];

after constructing the controllers (and their views) that the navigation controller will manage?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

各自安好 2024-11-03 17:01:23

您不需要 UIView 容器。如果想使用容器,您将需要 UIViewController。不管怎样,只需将导航控制器直接添加到数组中即可。稍后您可以从同一数组访问它们,以在另一个拆分视图上推送和弹出。

RootViewController* rootViewController = [[RootViewController alloc] init];
navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[rootViewController release];

splitVC = [[UISplitViewController alloc] init];

[window addSubview:splitVC.view];

TempViewController* tempViewController = [[TempViewController alloc] initWithNibName:@"TempViewController" bundle:nil];
detailNavController = [[UINavigationController alloc] initWithRootViewController:tempViewController];
[tempViewController release];

splitVC.viewControllers = [NSArray arrayWithObjects:navController, detailNavController, nil];

You don't need UIView containers. If wanted to use containers you would need UIViewControllers. Regardless just add the navigation controller to the array directly. Later you can access them from the same array to push and pop on the other split view.

RootViewController* rootViewController = [[RootViewController alloc] init];
navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[rootViewController release];

splitVC = [[UISplitViewController alloc] init];

[window addSubview:splitVC.view];

TempViewController* tempViewController = [[TempViewController alloc] initWithNibName:@"TempViewController" bundle:nil];
detailNavController = [[UINavigationController alloc] initWithRootViewController:tempViewController];
[tempViewController release];

splitVC.viewControllers = [NSArray arrayWithObjects:navController, detailNavController, nil];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文