我在应用程序委托中加载的视图控制器(在导航控制器中)与选项卡栏重叠
当应用程序加载到我的应用程序委托中时,我在初始化视图控制器时遇到问题。视图控制器加载正常,但它与底部的选项卡栏重叠。我是否需要创建另一个视图控制器并将其加载到应用程序委托中?我目前在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您尝试使用 UITabBarController,每个选项卡都有自己的根视图控制器(这些甚至可以是 UINavigationController 对象)。假设你有 self.tabBarController 的属性(我认为如果你正在做一个选项卡栏应用程序,它会在 Xcode 中默认创建),那么:
使用 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:
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!
[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 anavigationController
on it and then setviewController
for that navigation controller..........create an outlet of
tabBarController
inappDelegate
so that you can add it onwindow
. Pleas do not forget to make connection between components in Interface Builder.Thanks,