基于导航的应用程序中的选项卡栏(再次)

发布于 2024-08-06 23:24:36 字数 610 浏览 4 评论 0原文

这是我的问题:

我已经阅读了很多有关如何在基于导航的应用程序中使用选项卡栏的内容,但我仍然无法弄清楚。我尝试过使用和避免使用标签栏控制器,但我只是找不到解决方案。

我已经有一个基于导航的应用程序正在运行。我有几个 nib 文件(视图),每个文件都有自己的视图控制器,我以编程方式将其推送到导航控制器堆栈上。我需要其中一个视图有一个选项卡栏,允许我在其他视图之间切换。我了解选项卡栏的工作原理,并且我确实认为我需要的是使用选项卡栏控制器,因为它允许我定义与每个选项卡栏项目关联的视图控制器,并管理它们的所有内容。但是,我不知道该怎么做。

如果我确实在我的“tabBarViewController”中声明了一个选项卡栏控制器,在我的“tabBarView”中绘制选项卡栏控制器并将它们与IB链接,它会给我一个错误(我认为这是因为我还没有真正推送选项卡栏控制器的视图?我需要相当于“[window addSubView:[tabbarcontroller view]]?)的东西。在这种情况下,我需要知道的是如何在视图中“查看”选项卡栏控制器的顶视图控制器的视图我已经推送了控制器。

如果我尝试不使用选项卡栏控制器,正如我读过的那样,这是解决此问题的最佳方案,“我如何管理选项卡栏项目、它们之间的切换等,

我将非常感谢您 ”帮助。

Here is my problem:

I've read a lot about how to use a tab bar within a navigation based application, but i still can't figure it out. I have tried both to use and avoid using a tab bar controller, but i just can't find the solution.

I already have a navigation based app working. I have several nib files (views), each one with its own view controller, that i programmatically push onto the navigation controller stack. I need one of this views to have a tab bar that allows me to switch between some of the others. I understand how the tab bar works, and i do think what i need is to use a tab bar controller, since it would allow me to define the view controllers associated with each tab bar item, and manage all about them. However, i can't see how to do it.

If i do declare a tab bar controller in my "tabBarViewController", draw the tab bar controller in my "tabBarView" and link them with the IB, it will give me an error (I reckon this is because i haven't really pushed the tab bar controller's view? do i need something equivalent to "[window addSubView:[tabbarcontroller view]]?). In this case, all i need to know is how to "see" the tab bar controller's top view controller's view within a view controller i have already pushed.

If i try not to use a tab bar controller, as i have read is the best solution to this problem, ¿how do i manage tab bar items, the switchs between them, etc?

I would really appreciate your help.

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

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

发布评论

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

评论(3

两仪 2024-08-13 23:24:36

您无法将选项卡栏控制器推送到导航控制器堆栈上。只是没有支持的方法来做到这一点。

您可能需要考虑的是创建自己的 UITabBar 实例,然后使用符合 UITabBarDelegate 的委托。这样,只要用户选择选项卡栏项目,您的代理就会收到 tabBar:didSelectItem: 消息。不过,您必须自己管理该栏的 items NSArray,而不使用 IB。

一旦你弄清楚了这一点,剩下要做的就是像其他任何一样将常规 UIViewController 推送到你的导航堆栈上,然后让该控制器管理你的选项卡栏和委托。

You can't push a tab bar controller onto a navigation controller stack. There's just no supported way to do it.

What you may want to consider instead is creating your own instance of UITabBar, then using a delegate that conforms to UITabBarDelegate. That way, your delegate will receive the tabBar:didSelectItem: message whenever a tab bar item is selected by the user. You'll have to manage the NSArray of items for the bar yourself, though, without using IB.

Once you've got that figured out, all that's left to do is push a regular UIViewController onto your navigation stack like any other, and just have that controller manage your tab bar and delegate.

如梦 2024-08-13 23:24:36

我刚刚制作了一个带有 tabBar 控制器和 5 个 navController 的应用程序。您需要做的就是在 tabBar 控制器的第一个元素内加载笔尖和导航控制器。即使视图位于其中,您也可以隐藏 tabBar,并使其显示在您需要的视图中。

I just made an App with a tabBar controller and 5 navControllers. All you need to do is load the nibs and navigation controller inside the first element of the tabBar controller. You can HIDE the tabBar even if the views are inside it, and make it appear in the view you need it to.

吃兔兔 2024-08-13 23:24:36

您可以使用一些代码来完成此操作,如下所示:

FooViewController *foo = [[FooViewController alloc] init];
BarViewController *bar = [[BarViewController alloc] init];

UITabBarController *tabby = [[UITabBarController alloc] init];
[tabby setViewControllers:[NSArray arrayWithObjects:foo, bar, nil] animated:NO];
[self.navigationController pushViewController:tabby animated:YES];
[foo release];
[bar release];
[tabby release];

您也可以使用 IB 来完成此操作,只需从笔尖加载选项卡栏控制器即可。

我构建了一个示例项目来演示这一点,您可以从 http://s3.thismoment 下载它。 com/navtab.zip

You can do this with a bit of code, like so:

FooViewController *foo = [[FooViewController alloc] init];
BarViewController *bar = [[BarViewController alloc] init];

UITabBarController *tabby = [[UITabBarController alloc] init];
[tabby setViewControllers:[NSArray arrayWithObjects:foo, bar, nil] animated:NO];
[self.navigationController pushViewController:tabby animated:YES];
[foo release];
[bar release];
[tabby release];

You could probably do it with IB as well, just load the tab bar controller from a nib.

I built a sample project that demonstrates this in action, you can download it from http://s3.thismoment.com/navtab.zip

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