iPhone:TabBarController 作为第二级导航控制器

发布于 2024-09-01 02:57:30 字数 304 浏览 4 评论 0原文

我是 iPhone 开发新手。

我读过有关在窗口上实现选项卡栏控制器的教程(例如作为应用程序的主控制器)。但是如何创建一个选项卡栏控制器作为可以由导航栏控制器调用的“独立”UIViewController?

基本上,我的导航栏控制器有一个 UIViewController 数组,它显示在表中,然后在用户选择某个项目时加载适当的视图/控制器。

现在我希望这些加载的视图/控制器之一成为选项卡栏控制器。我该怎么做?

我不确定如何在应用程序委托中没有插座/实例的情况下自行创建选项卡栏控制器。

希望这是有道理的。谢谢。

I'm new to iphone development.

I've read tutorials about implementing a tab bar controller on the window (eg as the main controller for the app). But how can I create a tab bar controller as a 'standalone' UIViewController that can be called by a navigation bar controller?

Basically my navigation bar controller has an array of UIViewControllers that it displays in the table and then loads the appropriate view/controller when a user selects an item.

Now I want one of these loaded views/controllers to be a tab bar controller. How can I do this?

I'm not sure how to create a tab bar controller on its own without having an outlet/instance in the application delegate.

Hope that made sense. Thanks.

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

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

发布评论

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

评论(2

野味少女 2024-09-08 02:57:31

虽然之前的答案是正确的,但我想指出苹果不会对此感到满意:

您永远不想将选项卡栏控制器推送到导航控制器的导航堆栈上。这样做会产生一种不寻常的情况,即仅当特定视图控制器位于导航堆栈顶部时才会出现选项卡栏。选项卡栏被设计为持久的,因此这种瞬态方法可能会让用户感到困惑。

引用自: Apple View Controller 编程指南

阅读人机界面指南,您的应用可能会因“违反界面规则”而被拒绝。此外,您还必须手动处理所有 vieWillAppear/Disappear 等。我很确定还有另一种设计界面的方法。

问候,
保罗

Although previous answer was is correct, I'd just like to point out that Apple won't be happy with this:

You never want to push a tab bar controller onto the navigation stack of a navigation controller. Doing so creates an unusual situation whereby the tab bar appears only while a specific view controller is at the top of the navigation stack. Tab bars are designed to be persistent, and so this transient approach can be confusing to users.

Quotation from: Apple View Controller Programming Guide

Read Human Interface Guidelines, your app might be rejected for "breaking the interface rules". What's more, you'll also have to handle all the vieWillAppear/Disappear etc manually. I'm pretty sure there's another way of designing the interface.

Regards,
Paul

清风挽心 2024-09-08 02:57:31

你有两个选择。

第一的。创建 UITabBarController(一般 alloc-init 的东西)并将其推送到 UINavigationController。

第二。您可以创建自定义 UIViewController 并将 UITabBar 放置在那里。之后,您可以对其进行自定义并将该自定义 UIViewController 推送到导航控制器。代码如下所示:

UITabBar *tabBar = [[UITabBar alloc] initWithFrame:
    CGRectMake(0, self.view.frame.size.height - 49, 320, 49)];
tabBar.autoresizingMask = 
    UIViewAutoresizingFlexibleTopMargin | 
    UIViewAutoresizingFlexibleWidth;
[self.view addSubview:tabBar];

例如,您可以在 UIViewController 的 viewDidLoad 方法中使用类似的代码。
要处理选项卡更改事件,您必须实现 UITabBarDelegate 协议并将其分配给它(例如 UIViewController 本身):

tabBar.delegate = self;

之后,您必须实现

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item

帮助您捕获事件的方法。

You have two options.

First. Create UITabBarController (general alloc-init stuff) and push it to UINavigationController.

Second. You can create custom UIViewController and place UITabBar there. After that you can customize it and push that custom UIViewController to navigation controller. Code will look like this:

UITabBar *tabBar = [[UITabBar alloc] initWithFrame:
    CGRectMake(0, self.view.frame.size.height - 49, 320, 49)];
tabBar.autoresizingMask = 
    UIViewAutoresizingFlexibleTopMargin | 
    UIViewAutoresizingFlexibleWidth;
[self.view addSubview:tabBar];

You can use similar code in viewDidLoad method of UIViewController, for example.
To process tab change event, you'll have to implement UITabBarDelegate protocol and assign it (for example to UIViewController itself):

tabBar.delegate = self;

After that you'll have to implement

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item

method that'll help you to catch events.

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