代码中的 UITabBar 和 UINavigationController
我目前有一个 UITabBar,有 5 个屏幕调用 UIViews。该部分工作正常,但我想在其中几个中放入 UINavigationController 。我发现一些教程工作得很好,但它们都在 IB 中实现了它,我想如果可能的话避免这种情况。
我不知道在哪里实现 UINavigationController,我应该在带有 UITabBar 的 App Delegate 中执行它并从 UIView 调用导航控制器,还是应该在 UIView 类中创建它?
我尝试了大约 8 种不同的方法,但总是以导航栏不起作用、根本没有导航栏或应用程序崩溃而告终。
目前,我创建的选项卡栏如下所示:
tabBarController = [[UITabBarController alloc] init];
ScreenA *screenA = [[ScreenA alloc] initWithNibName:@"ScreenA" bundle:nil];
//more here
tabBarController.viewControllers = [NSArray arrayWithObjects:screenA, ...., nil];
[window addSubview:tabBarController.view];
在 initWithNibName 中,我有以下内容:
self.title = @"Screen A";
self.tabBarItem.image = [UIImage imageNamed:@"someImage.png"];
I've currently got a UITabBar with 5 screens calling UIViews. That part works fine but I want to put in a UINavigationController in a couple of them. I have found a few tutorials that work fine but all of them implement it in IB and I want to avoid that if possible.
I'm lost as to where to implement the UINavigationController, should I do it in the App Delegate with the UITabBar and call the navigation controller from the UIView or should I create it in the UIView class?
I've tried about 8 different ways and always ends up with either the Navbar not working, no nav bar at all or the app crashing.
Currently I create the tab bar like this:
tabBarController = [[UITabBarController alloc] init];
ScreenA *screenA = [[ScreenA alloc] initWithNibName:@"ScreenA" bundle:nil];
//more here
tabBarController.viewControllers = [NSArray arrayWithObjects:screenA, ...., nil];
[window addSubview:tabBarController.view];
And in the initWithNibName I have this:
self.title = @"Screen A";
self.tabBarItem.image = [UIImage imageNamed:@"someImage.png"];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,像这样做...
<代码>
Ok, do it like this...