导航栏未与 UITabBarController 中的 TTThumbsViewController 一起出现

发布于 2024-11-27 05:09:30 字数 934 浏览 1 评论 0原文

我试图将 TTThumbsViewController 放入 UITabBarController 中,但是当我这样做时,TTThumbsViewController 的导航栏不会显示。导航栏应该所在的位置只有空白。我只加载了 TTThumbsViewController 本身,并且导航栏加载得很好。我确信我错过了一个设置,但我不知道它是什么。

以下是我创建 UITabBarController 和 TTThumbsViewController 的操作:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.tabBarController = [[UITabBarController alloc] init];
    ThumbsViewController *thumbsViewController = [[ThumbsViewController alloc] init];
    UITabBarItem *thumbsTabBarItem = [[UITabBarItem alloc] initWithTitle:@"Thumbs" image:[UIImage imageNamed:@"icon.png"] tag:Thumbs];
    thumbsViewController.tabBarItem = thumbsTabBarItem;
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:thumbsViewController, nil];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

I'm trying to put a TTThumbsViewController inside a UITabBarController, but when I do, the TTThumbsViewController's NavigationBar doesn't show. There is just blank space where the NavigationBar should be. I've loaded just the TTThumbsViewController by itself, and the NavigationBar loads just fine. I'm sure I've just missed a setting, but I can't figure out what it is.

Here is what I'm doing to create the UITabBarController and the TTThumbsViewController:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.tabBarController = [[UITabBarController alloc] init];
    ThumbsViewController *thumbsViewController = [[ThumbsViewController alloc] init];
    UITabBarItem *thumbsTabBarItem = [[UITabBarItem alloc] initWithTitle:@"Thumbs" image:[UIImage imageNamed:@"icon.png"] tag:Thumbs];
    thumbsViewController.tabBarItem = thumbsTabBarItem;
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:thumbsViewController, nil];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

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

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

发布评论

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

评论(1

傲性难收 2024-12-04 05:09:30

如果您从 UITabController 加载 TTThumbsViewController,则需要自己创建 UINavigationController。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.tabBarController = [[UITabBarController alloc] init];
    ThumbsViewController *thumbsViewController = [[ThumbsViewController alloc] init];
    UITabBarItem *thumbsTabBarItem = [[UITabBarItem alloc] initWithTitle:@"Thumbs" image:[UIImage imageNamed:@"icon.png"] tag:Thumbs];
    thumbsViewController.tabBarItem = thumbsTabBarItem;

    UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:ThumbsViewController] autorelease];

    self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController, nil];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

If you're loading the TTThumbsViewController from a UITabController, you need to create the UINavigationController yourself.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.tabBarController = [[UITabBarController alloc] init];
    ThumbsViewController *thumbsViewController = [[ThumbsViewController alloc] init];
    UITabBarItem *thumbsTabBarItem = [[UITabBarItem alloc] initWithTitle:@"Thumbs" image:[UIImage imageNamed:@"icon.png"] tag:Thumbs];
    thumbsViewController.tabBarItem = thumbsTabBarItem;

    UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:ThumbsViewController] autorelease];

    self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController, nil];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文