• <bdo id='IjUho'></bdo><ul id='IjUho'></ul>
  • <legend id='IjUho'><style id='IjUho'><dir id='IjUho'><q id='IjUho'></q></dir></style></legend>
  • <small id='IjUho'></small><noframes id='IjUho'>

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

  • <tfoot id='IjUho'></tfoot>

        在应用程序启动时从情节提要中选择替代的第一

        时间:2023-05-30

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

              <tbody id='GhFIh'></tbody>

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

            • <bdo id='GhFIh'></bdo><ul id='GhFIh'></ul>

                1. 本文介绍了在应用程序启动时从情节提要中选择替代的第一个视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我刚刚开始使用 iOS 编程,到目前为止,我在这里找到的教程和答案对我前进有很大帮助.然而,这个特殊的问题让我整晚都在烦恼,我找不到感觉正确"的答案.

                  I've just started on iOS programming and so far the tutorials and answers I found here have been a great help to move forward. However, this particular problem has been bumming me all night and I can't find an answer that "feels right".

                  我正在编写一个连接到远程服务的应用程序,用户需要先登录才能使用它.当他们开始使用应用程序时,他们的第一个视图应该是登录对话框;当他们之前进行过身份验证时,他们会立即看到概览页面.

                  I'm writing an application that connects to a remote service and the users need to sign in before they can use it. When they start using the application, their first view should be the sign in dialog; when they've authenticated before, they immediately see the overview page.

                  该项目使用故事板——我认为这是一个很棒的特性——所以选择和加载根视图控制器的大部分代码都已经处理好了.我认为添加逻辑的最佳位置是 AppDelegate:

                  The project uses story boards - which I think is a great feature - so most of the code that selects and loads the root view controller is already taken care of. I thought the best place to add my logic is the application:didFinishLaunchingWithOptions: method of the AppDelegate:

                  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
                        (NSDictionary *)launchOptions
                  {
                      // select my root view controller here based on credentials present or not
                      return YES;
                  }
                  

                  但这带来了两个问题:

                  1. 在这个特定的委托方法中,根视图控制器已经根据故事板被选择(并加载?).我是否可以在加载过程中移到更早的位置以覆盖第一个视图控制器选择,或者这会使事情变得不必要地复杂化?

                  1. Inside this particular delegate method, the root view controller has already been selected (and loaded?) based on the story board. Could I move to an earlier spot in the loading process to override the first view controller selection or would that needlessly complicate matters?

                  要覆盖第一个视图控制器,我需要引用故事板,但我找不到比使用 storyboardWithName:bundle: 构造函数更好的方法UIStoryboard.感觉不对,应用程序应该已经有故事板的引用,但是我怎么才能访问它呢?

                  To override the first view controller I need a reference to the story board, but I couldn't find a better way than to use the storyboardWithName:bundle: constructor of UIStoryboard. That feels wrong, the application should already have a reference to the story board, but how can I access it?

                  更新

                  我解决了我遇到的第二个问题,因为我在这里找到了答案:

                  I worked out the second issue I was having, as I found my answer here:

                  UIStoryboard:获取活跃的故事板?

                  NSBundle *bundle = [NSBundle mainBundle];
                  NSString *sbFile = [bundle objectForInfoDictionaryKey:@"UIMainStoryboardFile"];
                  UIStoryboard *sb = [UIStoryboard storyboardWithName:sbFile bundle:bundle];
                  

                  以上将创建一个新的故事板实例;要获取活动实例,要简单得多:

                  The above will create a new story board instance; to get the active instance, it's a whole lot simpler:

                  UIStoryboard *sb = [[self.window rootViewController] storyboard];
                  

                  在故事板文件本身中,您必须为要加载的视图设置标识符,例如登录对话框.然后你像这样实例化视图:

                  In the story board file itself you have to set an identifier for the view you wish to load, e.g. LoginDialog. Afterwards you instantiate the view like this:

                  LoginViewController *login = [sb instantiateViewControllerWithIdentifier:@"LoginDialog"];
                  [self.window setRootViewController:login];
                  

                  在另一个视图控制器中,以下就足够了:

                  Within another view controller, the following suffices:

                  UIStoryboard *sb = self.storyboard;
                  LoginViewController *login = [sb instantiateViewControllerWithIdentifier:@"LoginDialog"];
                  [self presentViewController:login animated:NO completion:nil];
                  

                  推荐答案

                  只需重置窗口的根视图控制器即可

                  You can just reset the root view controller of the window

                  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
                        (NSDictionary *)launchOptions
                  {
                     if(your_condition) {
                         UIViewController *newRoot = [your implementation];
                         self.window.rootViewController = newRoot;
                     }
                     return YES;
                  }
                  

                  这对我有用,Xcode5.0.1

                  This is worked for me, Xcode5.0.1

                  这篇关于在应用程序启动时从情节提要中选择替代的第一个视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:performSegueWithIdentifier 和 sharedData 下一篇:使用故事板的优点和缺点

                  相关文章

                  最新文章

                    <bdo id='vnp0N'></bdo><ul id='vnp0N'></ul>
                2. <legend id='vnp0N'><style id='vnp0N'><dir id='vnp0N'><q id='vnp0N'></q></dir></style></legend>

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