我应该为每个选项卡栏使用单独的 UINavigationController

2024-05-01

根据Apple https://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/CombiningViewControllers.html,我可以结合UINavigationController and UITabBarController使用代码,例如

MyViewController1* vc1 = [[MyViewController1 alloc] init];
MyViewController2* vc2 = [[MyViewController2 alloc] init];
MyViewController3* vc3 = [[MyViewController3 alloc] init];

MyNavRootViewController* vc4 = [[MyNavRootViewController alloc] init];
UINavigationController* navController = [[UINavigationController alloc]
                        initWithRootViewController:vc4];

NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, vc3, navController, nil];
tabBarController.viewControllers = controllers;

在此设置中,仅vc4UINavigationController,但是如果我想要怎么办vc1-vc3还有UINavigationController?,我应该这样做吗..

MyViewController1* vc1 = [[MyViewController1 alloc] init];
UINavigationController* nv1 = [[UINavigationController alloc]
                        initWithRootViewController:vc1];

MyViewController1* vc2 = [[MyViewController2 alloc] init];
UINavigationController* nv2= [[UINavigationController alloc]
                        initWithRootViewController:vc2];

MyViewController1* vc3 = [[MyViewController3 alloc] init];
UINavigationController* nv3 = [[UINavigationController alloc]
                        initWithRootViewController:vc3];


NSArray* controllers = [NSArray arrayWithObjects:nv1, nv2, nv3, nil];
tabBarController.viewControllers = controllers;

这是正确的方法吗?


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];


// Override point for customization after application launch.

self.tabBarController = [[[UITabBarController alloc] init] autorelease];

 self.tabBarController.viewControllers = [self initializeTabBarItems];
self.navigationController = [[UINavigationController alloc]init];
[self.navigationController setNavigationBarHidden:YES];
self.window.rootViewController = self.navigationController;
[self.navigationController pushViewController:_tabBarController animated:YES];
[self.window makeKeyAndVisible];
return YES;
}
- (NSArray *)initializeTabBarItems
{
NSArray * retval;

/* Initialize view controllers */
UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];
UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease];
UIViewController *viewController3 = [[[ThirdViewController alloc]initWithNibName:@"ThirdViewController" bundle:nil]autorelease];
UIViewController *viewController4 = [[[FourthViewController alloc] initWithNibName:@"FourthViewController" bundle:nil] autorelease];
UIViewController *viewController5  = [[[FivfthViewController alloc] initWithNibName:@"FivfthViewController" bundle:nil] autorelease];


/* Initialize navigation controllers */
UINavigationController * navigationController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
UINavigationController * navigationController2 = [[UINavigationController alloc] initWithRootViewController:viewController2];
UINavigationController * navigationController3 = [[UINavigationController alloc] initWithRootViewController:viewController3];
UINavigationController * navigationController4 = [[UINavigationController alloc] initWithRootViewController:viewController4];
UINavigationController * navigationController5 = [[UINavigationController alloc] initWithRootViewController:viewController5];

/*  Release View Controllers */
[viewController1 release];
[viewController2 release];
[viewController3 release];
[viewController4 release];
[viewController5 release];

/* Stuff Navigation Controllers into return value */
retval = [NSArray arrayWithObjects:viewController1,viewController2,viewController3,viewController4,viewController5,nil];

/* Release Navigation Controllers */
[navigationController1 release];
[navigationController2 release];
[navigationController3 release];
[navigationController4 release];
[navigationController5 release];

return (retval);
}

你可以试试这个......

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

我应该为每个选项卡栏使用单独的 UINavigationController 的相关文章

  • 用于具有转换的非导航应用程序的视图控制器/NIB 架构?

    我正在修补一个 iPad 应用程序 就像许多 iPad 应用程序一样 它不使用 UINavigation 根视图控制系统 因此我没有每个应用程序 视图 的自然所有权 我基本上有两个基本视图 文档列表视图和文档编辑视图 我正在使用 UIVie
  • Objective C 中类别是如何实现的?

    作为一名程序员 我知道如何使用类别 但我很好奇它们是如何实现的 编译器是否将它们编译为对类替换方法 http developer apple com library mac documentation Cocoa Reference Obj
  • 在 github 上下载 ZIP 时没有 .xcodeproj 文件

    我正在尝试将我的 GitHub 项目放入 Xcode 中 当我从 GitHub 下载时 zip 文件不包含任何 xcodeproj 文件 另外 即使我在 xcode 上登录 GitHub 克隆 下载时也没有 在 Xcode 中打开 选项 如
  • 将 Armadillo C++ 库导入 Xcode

    我是 Mac 用户 正在尝试安装和导入 C Armadillo 库 以下是我到目前为止所采取的步骤 1 我从其网站下载了犰狳库 2 我仔细阅读了下载文件中的 Readme txt 文件 解释了如何安装它 3 我使用CMake将犰狳下载文件制
  • 如何将CIFilter应用到UIView上?

    根据Apple docs 过滤属性CALayer不支持iOS 当我使用正在申请的应用程序之一时CIFilter to UIView即 Splice Funimate 和 Artisto 的视频编辑器 Videoshow FX 这意味着我们可
  • iPhone SDK中的短信正文

    我需要从我的 iPhone 应用程序发送短信 SMS 的正文是以编程方式创建的 因此 当我点击按钮时 短信应用程序应该打开 并在其中预先输入我的消息 有人知道怎么做吗 需要帮忙 提前致谢 世宾 您无法设置短信正文 根据官方 SDK 您可以从
  • Swift:协议、结构、类

    我开始学习 Swift 语言 但在理解协议 结构和类方面遇到了困难 我来自 Android 方面的编程 所以我相信 Swift 协议基本上是 Java 接口 其中每一个的正确用例是什么 这些类比并不 完全 正确 但这就是我所理解的要点 是的
  • 使用 ZBarSDK 时 iPhone 相机失去自动对焦功能

    我正在开发一个应用程序 用户可以选择是否要扫描条形码或拍摄某物的照片 为了拍照 我正在使用UIImagePickerController照常 为了扫描条形码 我使用 ZbarSDK 1 2ZBarReaderViewController 拍
  • UILabel 中的文本未垂直居中

    我使用以下代码创建了一个标签 func setupValueLabel valueLabel numberOfLines 1 valueLabel font UIFont name Avenir Black size 50 valueLab
  • cameraOverlayView 防止使用 allowedEditing 进行编辑

    在我的应用程序中 使用以下行在拍摄照片后对其进行编辑 移动和缩放 效果很好 imagePicker setAllowsEditing YES 但如果我还使用cameraOverlayView 则编辑模式将不再起作用 屏幕出现 但平移和捏合手
  • 如何在Sprite Kit中实现鼠标关节?

    我已经在 iOS 上用 Cocos2d Box2d 编写了拖放功能的工作实现 我需要将它移植到 Sprite Kit 逻辑非常基本 当用户触摸屏幕时 找到手指下的精灵 在找到的精灵和场景的物理体之间创建鼠标关节 将关节的目标设置为触摸位置
  • 检查 Objective-C 块类型?

    这主要是出于好奇 我不太确定它的实际用途是什么 但就这样吧 由于块也是 Objective C 对象 是否可以检查它们的类型 也就是说 它是否响应isKindOfClass 消息以及如何使用该消息来处理块 我天真的以为事情大概是这样的 vo
  • iOS Swift 和 reloadRowsAtIndexPaths 编译错误

    我与 xCode Swift 陷入僵局并刷新 UITableView 的单行 这条线有效 self tableView reloadData 而这条线没有 self tableView reloadRowsAtIndexPaths curr
  • cordova插件条码扫描仪打不开扫描

    我的条形码扫描仪插件有问题 我不是天才 我不太了解如何编写网络应用程序 我使用phonegap和cordova 并且尝试制作一个网络应用程序 在单击链接后扫描条形码 我之前已经使用此命令行安装了该插件 cordova plugin add
  • 当 ViewController 从 UIStoryboard 实例化时,isMemberOfClass 返回 no

    我有一个 OCUnit 测试类 PatientTestViewControllerTests 下面是界面 interface PatientTestViewControllerTests SenTestCase property nonat
  • WKWebview 中的 iCLoud 文档选择器关闭容器视图

    我有一个 WKWebview 加载基于 Web 的 UI 我希望用户能够从其 iCloud 文档上传文件 我已授予正确的权限 并且可以浏览 iCloud 文档 但是 当我选择文件或单击取消按钮时 文档选择器视图也会关闭 WKWebview
  • 无需越狱即可检测iOS9上哪个应用程序处于前台

    我正在尝试记录用户在 iOS9 上的个人应用程序使用情况 我宁愿它不会使用越狱有限的解决方案 不言自明 在越狱手机上执行此应用程序的变体应该不难 https www andyibanez com create mobilesubstrate
  • 如果我在 iTunes Connect 中点击“拒绝二进制文件”来提交更新的二进制文件,我会失去排队的位置吗?

    我已通过 iTunes Connect 向 App Store 提交了一个应用程序 状态为 审核中 我不知道这是否意味着他们真的开始关注它 我怀疑这只是意味着它已被放入审阅者队列中 在它发布之前我想添加一个调整 但是 如果这意味着点击 拒绝
  • 下载进度条在 iOS 企业发行版中没有改变进度

    我正在通过企业分发开发和分发 iPad 应用程序 它们下载并执行良好 因此一切正常 Web 链接 ipa 文件 plist 文件 配置 问题 是 当用户单击链接进行下载时 iPad 中显示下载进度的进度条显示 正在等待 但却是空的并且永远不
  • 如何观察UserDefaults的变化?

    我有一个 ObservedObject在我看来 struct HomeView View ObservedObject var station Station var body some View Text self station sta

随机推荐