Objective-c 如何正确管理多个视图和控制器

发布于 2024-11-06 22:05:14 字数 287 浏览 4 评论 0原文

我有一个应用程序,最初有一个 TabBarController,每个选项卡都是一个 ViewController,每个选项卡都有一个调用其他控制器的按钮。

那么我该如何构建这个呢?有一个主要的 rootviewController (如果是的话,怎么办?)?或者在 appdelegate 中仅调用 tabBarController 并在选项卡内的每个 viewController 中调用其他控制器?

让我能够灵活地前进、后退和转换视图的最佳方法是什么?

不知道我是否说清楚了...

谢谢大家。

I have an aplication which initially there's a TabBarController, each tab is a ViewController and every one has a button which calls other controllers.

So how am I supose to structure this? Having one main rootviewController (if so, how?)? Or calling in the appdelegate only the tabBarController and in each the viewControllers inside the tab call the other controllers?

What's the best way so I can advance, go back and transition views nimbly?

Don't know if I made myself clear...

Thanks guys.

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

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

发布评论

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

评论(1

等待圉鍢 2024-11-13 22:05:14

一般来说,您将从名为“选项卡栏应用程序”的模板开始,从 Xcode 4 开始,首先加载 MainWindow Nib,它包含一个选项卡栏,并且选项卡栏在 IB 中设置为具有 2 个视图控制器,称为“FirstViewController”,和“SecondViewController”...

如果适合您,您可以遵循该模式,否则您可能希望从基于视图的应用程序开始并添加您自己的选项卡栏。我个人发现通过 UITabBarDelegate 控制选项卡栏更容易,特别是如果您打算做一些稍微深奥的事情。

编辑:

如果您计划加载导航控制器堆栈或单个模态视图,则基本上是两种方法之一。

1)

ThirdViewController * controller = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
UINavigationController * myNavigationController = [[UINavigationController alloc] initWithRootViewController:controller];

[self presentModalViewController:myNavigationController animated:YES];
[controller release];
[myNavigationController release];

2)

ThirdViewController * controller = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
[self presentModalViewController:controller animated:YES];
[controller release];

无论哪种方式,都可以通过在调用当前模态的视图控制器上调用以下命令来返回选项卡环境。

[自己
missModalViewControllerAnimated:YES];

Generally you will start with the Template called "Tab Bar Application" and as of Xcode 4 starts by loading the MainWindow Nib, which hold a tab bar and the tab bar is set up in IB to have 2 view controllers, called "FirstViewController", and "SecondViewController"...

You can follow that pattern if it suites you, otherwise you may want to start with a view based application and add your own tab bar. I personally find it to be easier to control the tab bar, through the UITabBarDelegate, especially if you plan to do anything slightly esoteric.

Edit:

Basically one of two ways, if you plan to load a Navigation controller stack, or a single modal view.

1)

ThirdViewController * controller = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
UINavigationController * myNavigationController = [[UINavigationController alloc] initWithRootViewController:controller];

[self presentModalViewController:myNavigationController animated:YES];
[controller release];
[myNavigationController release];

2)

ThirdViewController * controller = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
[self presentModalViewController:controller animated:YES];
[controller release];

either way get back to the Tab environment by calling the following on the view controller that is calling present modal.

[self
dismissModalViewControllerAnimated:YES];

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