UITabBar 中的单个选项卡不包含 UINavigationBar

发布于 2024-12-27 19:54:13 字数 1064 浏览 1 评论 0原文

我有一个非常奇怪的问题。我在 UITabBar 中编写了一个带有五个选项卡的应用程序。当我设置 TabBarController 的 viewControllers 属性时,我设置了五个 UINavigationControllers,这样每个选项卡中都会有一个 UINavigationController

其中四个选项卡可以完美运行。当我启动并切换到该选项卡时,导航栏就在那里。但是,其中一个选项卡并不包含我期望的 UINavigationBar,我无法理解为什么,因为我初始化它的方式与初始化所有其他选项卡的方式完全相同。

以下是 AppDelegate.m 文件中用于初始化各个视图控制器的一些示例代码:

    SpotFilterViewController *spotList = [[SpotFilterViewController alloc] init];
    navigationController = [[UINavigationController alloc] initWithRootViewController:spotList];

    [tabs addObject:navigationController];
    [navigationController release];
    [spotList release];

    MySpotViewController *mySpot = [[MySpotViewController alloc] initWithSpot:nil];
    navigationController = [[UINavigationController alloc] initWithRootViewController:mySpot];

    [tabs addObject:mySpot];
    [navigationController release];
    [mySpot release];

注意:navigationController 已在上面声明。

其他人以前遇到过这个问题吗?或者有人知道为什么会发生这种情况?非常感谢任何帮助。谢谢!

I'm having a really strange issue. I've written an app with five tabs in a UITabBar. When I set the TabBarController's viewControllers property, I set it with five UINavigationControllers, so that each tab will have a UINavigationController within it.

Four of the tabs have it working perfectly. The navigation bar is there when I launch and switch to that tab. However, one of the tabs does not contain the UINavigationBar as I expected it to, and I can't understand why, because I initialized it exactly the same way I initialized all the others.

Here's some sample code from the AppDelegate.m file of initializing the individual view controllers:

    SpotFilterViewController *spotList = [[SpotFilterViewController alloc] init];
    navigationController = [[UINavigationController alloc] initWithRootViewController:spotList];

    [tabs addObject:navigationController];
    [navigationController release];
    [spotList release];

    MySpotViewController *mySpot = [[MySpotViewController alloc] initWithSpot:nil];
    navigationController = [[UINavigationController alloc] initWithRootViewController:mySpot];

    [tabs addObject:mySpot];
    [navigationController release];
    [mySpot release];

Note: navigationController was declared above.

Anyone else run into this problem before? Or anyone have any idea why this might be happening? Any help is much appreciated. Thanks!

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

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

发布评论

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

评论(1

看海 2025-01-03 19:54:13

问题是你正在这样做:

[tabs addObject:mySpot];

而不是这样:

[tabs addObject:navigationController];

The problem is that you are doing this:

[tabs addObject:mySpot];

instead of this:

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