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

      1. <small id='Ms6v8'></small><noframes id='Ms6v8'>

        • <bdo id='Ms6v8'></bdo><ul id='Ms6v8'></ul>
        <tfoot id='Ms6v8'></tfoot>

        从应用程序委托获取当前视图控制器(模式是可能的)

        时间:2023-07-28
          • <small id='7sAwD'></small><noframes id='7sAwD'>

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

                  <legend id='7sAwD'><style id='7sAwD'><dir id='7sAwD'><q id='7sAwD'></q></dir></style></legend>
                  本文介绍了从应用程序委托获取当前视图控制器(模式是可能的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我知道要从应用委托中获取当前视图控制器,我可以使用为我的应用设置的 navigationController 属性.但是,在我的应用程序中的许多地方都可能出现了模态导航控制器.有什么方法可以从应用程序委托中检测到这一点,因为当前导航控制器将与应用程序委托持有引用的导航控制器不同?

                  I know that to get the current view controller from the app delegate, I can use the navigationController property I have set up for my app. However, it's possible in many places throughout my app that a modal navigation controller could have been presented. Is there any way to detect this from the app delegate, since the current navigation controller will be different from the one to which the app delegate holds a reference?

                  推荐答案

                  建议你使用NSNofiticationCenter.

                  I suggest you use NSNofiticationCenter.

                  //in AppDelegate:
                  @interface AppDelegate()
                  {
                      ...
                      id lastViewController;
                      ...
                  }
                  
                  @implementation AppDelegate
                  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
                  {
                      ...
                      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleCurrentViewController) name:@"CurrentViewController" object:nil];
                      ...
                  }
                  
                  - (void)handleCurrentViewController:(NSNotification *)notification {
                      if([[notification userInfo] objectForKey:@"lastViewController"]) {
                          lastViewController = [[notification userInfo] objectForKey:@"lastViewController"];
                      }
                  }
                  
                  - (void)applicationDidEnterBackground:(UIApplication *)application
                  {    
                      NSLog(@"last view controller is %@", [(UIViewController *)lastViewController class]);
                  }
                  @end
                  
                  //in every ViewController you want to detect
                  @implementation SomeViewController
                  ...
                  - (void) viewWillDisappear:(BOOL)animated {
                      [super viewWillDisappear:animated];
                      [[NSNotificationCenter defaultCenter] postNotificationName:@"CurrentViewController" object:nil userInfo:[NSDictionary dictionaryWithObjectsAndKeys:self, @"lastViewController", nil]];
                  }
                  ...
                  @end
                  

                  这篇关于从应用程序委托获取当前视图控制器(模式是可能的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 ARC 下将代表设置为零? 下一篇:属性“分配";和“保留"代表

                  相关文章

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

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

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