我在应用程序委托中加载的视图控制器(在导航控制器中)与选项卡栏重叠

发布于 2024-10-31 10:47:02 字数 701 浏览 0 评论 0原文

当应用程序加载到我的应用程序委托中时,我在初始化视图控制器时遇到问题。视图控制器加载正常,但它与底部的选项卡栏重叠。我是否需要创建另一个视图控制器并将其加载到应用程序委托中?我目前在 MainWindow.xib 中设置了一个 tabBarController,其中包含导航控制器,其中包含视图控制器。

这是我的代码...

在我的 didFinishLaunchingWithOptions 中,我有:

sub = [[SubGabViewController alloc] initWithNibName:@"SubGabViewController" bundle:nil];
nav = [[UINavigationController alloc] initWithRootViewController:sub];
[window addSubview:nav.view];

应该是这样的吗?

sub = [[SubGabViewController alloc] initWithNibName:@"SubGabViewController" bundle:nil];
nav = [[UINavigationController alloc] initWithRootViewController:sub];
[newViewController.view addSubview:nav.view];

谢谢!

I'm having trouble initializing a viewcontroller when the app loads in my app delegate. The viewcontroller loads okay, but it overlaps the tabbar that I have at the bottom. Do I need to create another viewcontroller and have it load into that in the app delegate? I currently have a tabBarController set up in my MainWindow.xib, which contains Navigation controllers and inside those are viewControllers.

Here is my code...

In my didFinishLaunchingWithOptions I have:

sub = [[SubGabViewController alloc] initWithNibName:@"SubGabViewController" bundle:nil];
nav = [[UINavigationController alloc] initWithRootViewController:sub];
[window addSubview:nav.view];

Should it be something like?

sub = [[SubGabViewController alloc] initWithNibName:@"SubGabViewController" bundle:nil];
nav = [[UINavigationController alloc] initWithRootViewController:sub];
[newViewController.view addSubview:nav.view];

Thanks!

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

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

发布评论

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

评论(2

可是我不能没有你 2024-11-07 10:47:02

如果您尝试使用 UITabBarController,每个选项卡都有自己的根视图控制器(这些甚至可以是 UINavigationController 对象)。假设你有 self.tabBarController 的属性(我认为如果你正在做一个选项卡栏应用程序,它会在 Xcode 中默认创建),那么:

sub = [[SubGabViewController alloc] initWithNibName:@"SubGabViewContrller" bundle:nil];
nav = [[UINavigationContoller alloc] initWithRootViewController:sub];
[self.tabBarController setViewControllers:[NSArray arrayWithObject:nav] animated:NO];
self.window.rootViewController = self.tabBarController;
// Clean up memory here... only if you don't need references to them
[sub release];
[nav release];

使用 setViewControllers:animated: 你可能应该在 NSArray 中包含额外的视图控制器,否则你最终会出现一个仅包含一项的选项卡栏!

If you're trying to use a UITabBarController, each tab has its own root view controller (these can even be UINavigationController objects). Assuming you have a property for self.tabBarController (I think this gets created by default in Xcode if you are doing a tab-bar app), then:

sub = [[SubGabViewController alloc] initWithNibName:@"SubGabViewContrller" bundle:nil];
nav = [[UINavigationContoller alloc] initWithRootViewController:sub];
[self.tabBarController setViewControllers:[NSArray arrayWithObject:nav] animated:NO];
self.window.rootViewController = self.tabBarController;
// Clean up memory here... only if you don't need references to them
[sub release];
[nav release];

With setViewControllers:animated: you should probably include additional view controllers in the NSArray, otherwise you'll end up with a tab bar only containing one item!

淡忘如思 2024-11-07 10:47:02

[window addSubview:tabBarController.view]; 是对的......

而不是使用代码添加导航控制器......你应该从 Interface Builder 添加它......在界面中builder 删除 tabBarItem 并在其上添加 navigationController ,然后为该导航控制器设置 viewController .........

创建appDelegate 中的 tabBarController 出口,以便您可以将其添加到 window 上。请不要忘记在 Interface Builder 中建立组件之间的连接。

谢谢,

[window addSubview:tabBarController.view]; would be right......

Rather than adding navigation controller using code..... you should add it from Interface Builder.... in interface builder remove the tabBarItem and add a navigationController on it and then set viewController for that navigation controller..........

create an outlet of tabBarController in appDelegate so that you can add it on window. Pleas do not forget to make connection between components in Interface Builder.

Thanks,

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