代码中的 UITabBar 和 UINavigationController

发布于 2024-09-01 11:16:31 字数 766 浏览 1 评论 0原文

我目前有一个 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 技术交流群。

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

发布评论

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

评论(1

﹂绝世的画 2024-09-08 11:16:31

好吧,像这样做...
<代码>

    tabBarController = [[UITabBarController alloc] init];    

searchTableViewController = [[SearchTableViewController alloc] init];
    UINavigationController *searchTableNavController = [[[UINavigationController alloc] initWithRootViewController:searchTableViewController] autorelease];
[searchTableViewController release];                                                              

searchMapViewController = [[SearchMapViewController alloc] init];   
UINavigationController *mapTableNavController = [[[UINavigationController alloc] initWithRootViewController:searchMapViewController] autorelease];
[searchMapViewController release];                                                    


tabBarController.viewControllers = [NSArray arrayWithObjects:searchTableNavController, mapTableNavController, nil]; 

Ok, do it like this...

    tabBarController = [[UITabBarController alloc] init];    

searchTableViewController = [[SearchTableViewController alloc] init];
    UINavigationController *searchTableNavController = [[[UINavigationController alloc] initWithRootViewController:searchTableViewController] autorelease];
[searchTableViewController release];                                                              

searchMapViewController = [[SearchMapViewController alloc] init];   
UINavigationController *mapTableNavController = [[[UINavigationController alloc] initWithRootViewController:searchMapViewController] autorelease];
[searchMapViewController release];                                                    


tabBarController.viewControllers = [NSArray arrayWithObjects:searchTableNavController, mapTableNavController, nil]; 

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