<bdo id='tpyfj'></bdo><ul id='tpyfj'></ul>
  1. <legend id='tpyfj'><style id='tpyfj'><dir id='tpyfj'><q id='tpyfj'></q></dir></style></legend>

      <i id='tpyfj'><tr id='tpyfj'><dt id='tpyfj'><q id='tpyfj'><span id='tpyfj'><b id='tpyfj'><form id='tpyfj'><ins id='tpyfj'></ins><ul id='tpyfj'></ul><sub id='tpyfj'></sub></form><legend id='tpyfj'></legend><bdo id='tpyfj'><pre id='tpyfj'><center id='tpyfj'></center></pre></bdo></b><th id='tpyfj'></th></span></q></dt></tr></i><div id='tpyfj'><tfoot id='tpyfj'></tfoot><dl id='tpyfj'><fieldset id='tpyfj'></fieldset></dl></div>
    1. <tfoot id='tpyfj'></tfoot>

      <small id='tpyfj'></small><noframes id='tpyfj'>

      如何使用 Interface Builder 添加导航控制器?

      How to add a Navigation Controller with Interface Builder?(如何使用 Interface Builder 添加导航控制器?)
    2. <i id='qU0vM'><tr id='qU0vM'><dt id='qU0vM'><q id='qU0vM'><span id='qU0vM'><b id='qU0vM'><form id='qU0vM'><ins id='qU0vM'></ins><ul id='qU0vM'></ul><sub id='qU0vM'></sub></form><legend id='qU0vM'></legend><bdo id='qU0vM'><pre id='qU0vM'><center id='qU0vM'></center></pre></bdo></b><th id='qU0vM'></th></span></q></dt></tr></i><div id='qU0vM'><tfoot id='qU0vM'></tfoot><dl id='qU0vM'><fieldset id='qU0vM'></fieldset></dl></div>

      <small id='qU0vM'></small><noframes id='qU0vM'>

        <bdo id='qU0vM'></bdo><ul id='qU0vM'></ul>

        <tfoot id='qU0vM'></tfoot>

        • <legend id='qU0vM'><style id='qU0vM'><dir id='qU0vM'><q id='qU0vM'></q></dir></style></legend>
            <tbody id='qU0vM'></tbody>

                本文介绍了如何使用 Interface Builder 添加导航控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                1.步骤: 创建一个新的 UIViewController:
                - Xcode -> 新建文件... -> Cocoa Touch 类 -> UIViewController
                - 名称:MyViewController

                1. Step: Create a new UIViewController:
                - Xcode -> New File... -> Cocoa Touch Class -> UIViewController
                - Name: MyViewController

                <强>2.步骤: 将导航控制器"(UINavigationController)从库中拖放到 MyViewController.xib

                2. Step: Drag and drop a "Navigation Controller" (UINavigationController) from the Library to MyViewController.xib

                3.Step:我确定,我必须做一些事情才能正确连接导航控制器,不是吗?

                3.Step: I'm sure, I have to do something to connect the Navigation Controller correctly, isn't it?

                4.Step:尝试以模态对话框的形式启动新的 View Controller:

                4.Step: Try to start the new View Controller as a modal dialog:

                MyViewController *myViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
                NSLog(@"navContr: %@", myViewController.navigationController);
                [self.navigationController presentModalViewController: myViewController animated:YES]; 
                

                结果:navContr: nil"

                Result: "navContr: nil"

                5.Step:可以看到新的模态视图(MyViewController),但是没有NavigationController,也没有UINavigationBar.

                5.Step: You can see the new modal view (MyViewController), but there's no NavigationController and no UINavigationBar.

                非常感谢您的帮助!

                更新 1:

                6.Step:我将新的 UIViewController (ViewNavi2) 设置为根视图控制器":

                6.Step: I set a new UIViewController (ViewNavi2) as "Root View Controller":

                7.Step: 我在 MyViewController 类中定义了一个 IBOutlet UINavigationController *navigationController 并配置 xib:Navigation Controller -> Connections -> Referencing Outlets

                7.Step: I define a IBOutlet UINavigationController *navigationController in the class MyViewController and configure the xib: Navigation Controller -> Connections -> Referencing Outlets

                但是我的导航控制器仍然是 nil :-(

                But my Navigation Controller is still nil :-(

                MyViewController *myViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
                NSLog(@"navContr: %@", myViewController.navigationController);
                // -> "navContr: nil"
                

                推荐答案

                我也想在 NIB 文件中包含导航控制器,但 Apple 文档只说它不是最佳的"而没有实际解释如何做.我希望我的主选项卡式窗口调用包含典型导航控件的模式窗口,而无需以编程方式定义导航控制器.我将分享我是如何做到的.

                I also wanted to include the navigation controller in the NIB file, but all that the Apple documentation said was that it is "not optimal" without actually explaining how to do it. I wanted my main tabbed window to call up a modal window containing the typical navigation controls without defining the navigation controller programmatically. I'll share how I did it.

                您的代码与我的非常相似,因为我还在 MyViewController 中定义了一个 IBOutlet UINavigationController *navigationController.在 Interface Builder 中,我只是在根视图控制器中定义了我的视图,并将 File's Owner->view 设置为该视图定义.

                Your code was very similar to mine, as I also defined an IBOutlet UINavigationController *navigationController in MyViewController. From Interface Builder, I simply defined my view in the root view controller and set the File's Owner->view to that view definition.

                与您的代码类似,我在父窗口中执行了以下操作:

                And similarly to your code, I did the following in my parent window:

                MyViewController *myViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
                [self presentModalViewController:myViewController animated:YES];
                

                (我在 self 上调用 presentModelViewController,我不知道你为什么有 self.navigationController.)当我测试这个时,结果是我的视图是从 NIB 文件加载的,但是导航栏不见了.MyViewController 中的另一行代码修复了这个问题:

                (I am calling presentModelViewController on self, I don't know why you had self.navigationController.) When I tested this, the result was that my view was loaded from the NIB file, but the navigation bar was missing. One more line of code in MyViewController fixed this:

                - (void)viewDidLoad {
                    [super viewDidLoad];
                
                    [self setView:myNavigationController.view];
                
                }
                

                我在这里所做的只是将 MyViewController 的视图设置为指向 myNavigationController.view,其中包含 NIB 文件中定义的所有内容,包括导航控制器.

                All I am doing here, is setting MyViewController's view to point to myNavigationController.view, which contains everything that was defined in the NIB file, including the navigation controller.

                这篇关于如何使用 Interface Builder 添加导航控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                UINavigationController inside a UITabBarController inside a UISplitViewController presented modally on iPhone(UISplitViewController 内的 UITabBarController 内的 UINavigationController 以模态方式呈现在 iPhone 上) - IT屋-程序员软件开发技术分
                ViewController in UINavigationController orientation change(UINavigationController 中的 ViewController 方向更改)
                Custom back button in UINavigationController(UINavigationController 中的自定义后退按钮)
                How to add a navigation controller programmatically in code but not as initial view controller(如何在代码中以编程方式添加导航控制器,但不作为初始视图控制器)
                How to get the previous viewcontroller that pushed my current view(如何获取推送我当前视图的上一个视图控制器)
                The correct way to set a light status bar text color in iOS 7 based on different ViewControllers(iOS 7中基于不同ViewControllers设置灯光状态栏文字颜色的正确方法)
                <legend id='ICBHO'><style id='ICBHO'><dir id='ICBHO'><q id='ICBHO'></q></dir></style></legend>

                      <tbody id='ICBHO'></tbody>
                      • <bdo id='ICBHO'></bdo><ul id='ICBHO'></ul>
                          <tfoot id='ICBHO'></tfoot>
                          <i id='ICBHO'><tr id='ICBHO'><dt id='ICBHO'><q id='ICBHO'><span id='ICBHO'><b id='ICBHO'><form id='ICBHO'><ins id='ICBHO'></ins><ul id='ICBHO'></ul><sub id='ICBHO'></sub></form><legend id='ICBHO'></legend><bdo id='ICBHO'><pre id='ICBHO'><center id='ICBHO'></center></pre></bdo></b><th id='ICBHO'></th></span></q></dt></tr></i><div id='ICBHO'><tfoot id='ICBHO'></tfoot><dl id='ICBHO'><fieldset id='ICBHO'></fieldset></dl></div>

                          <small id='ICBHO'></small><noframes id='ICBHO'>