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

标签 iphone objective-c ios uinavigationcontroller uitabbarcontroller

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

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

下面是 AppDelegate.m 文件中初始化各个 View Controller 的一些示例代码:

    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 是在上面声明的。

以前有其他人遇到过这个问题吗?或者有人知道为什么会这样吗?任何帮助深表感谢。谢谢!

最佳答案

问题是你这样做:

[tabs addObject:mySpot];

而不是这个:

[tabs addObject:navigationController];

关于iphone - UITabBar 中的单个选项卡不包含 UINavigationBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8888509/

相关文章:

iPhone : Unable to copy from MainBundle to NSDocumentDirectory

iphone - xcode 中的自动应用程序测试

php - 与 Core Data SQLite 文件交互的 Web 服务器代码?

ios - 创建登录页面并存储 token 字符串

ios - iPhone/iPad 上 UIActivityIndi​​cator 下的阴影

iphone - UITableView 中的 Obj-C iPhone UISegmentedControl

iphone - 从右/左动画 presentModalViewController

iphone - 从 NSURL 下载时如何处理非响应式 UI

用于测试的 iOS ipa 发行版

ios - Apple Watch 上的图像