<legend id='F7wgI'><style id='F7wgI'><dir id='F7wgI'><q id='F7wgI'></q></dir></style></legend>

    • <bdo id='F7wgI'></bdo><ul id='F7wgI'></ul>
  • <small id='F7wgI'></small><noframes id='F7wgI'>

    <tfoot id='F7wgI'></tfoot>

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

      2. 从应用委托中获取当前视图控制器

        时间:2023-07-28

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

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

                  <tbody id='vlQei'></tbody>
                <legend id='vlQei'><style id='vlQei'><dir id='vlQei'><q id='vlQei'></q></dir></style></legend>
                1. <small id='vlQei'></small><noframes id='vlQei'>

                  本文介绍了从应用委托中获取当前视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 ios 新手.我需要从应用程序委托中知道当前的视图控制器.我对此一无所知,也不知道如何实现它.我正在使用此代码来实现这一点,但它返回空值.我跟着这个链接-从应用委托(modal是可能的)需要帮助.

                  i am new to ios. I need to know the current view controller from app delegate.. i have no idea about this and i don't knowto implement this. i am using this code toimplemnt this but it return null values. I followed this link- Get current view controller from the app delegate (modal is possible) need help.

                  推荐答案

                  这是我用来查找用户最有可能与之交互的当前视图控制器:

                  This is what I use for finding the current view controller that the user is most likely interacting with:

                  UIViewController+Utils.h

                  #import <UIKit/UIKit.h>
                  
                  @interface UIViewController (Utils)
                  
                  +(UIViewController*) currentViewController;
                  
                  @end
                  

                  UIViewController+Utils.m

                  #import "UIViewController+Utils.h"
                  
                  @implementation UIViewController (Utils)
                  
                  +(UIViewController*) findBestViewController:(UIViewController*)vc {
                  
                      if (vc.presentedViewController) {
                  
                          // Return presented view controller
                          return [UIViewController findBestViewController:vc.presentedViewController];
                  
                      } else if ([vc isKindOfClass:[UISplitViewController class]]) {
                  
                          // Return right hand side
                          UISplitViewController* svc = (UISplitViewController*) vc;
                          if (svc.viewControllers.count > 0)
                              return [UIViewController findBestViewController:svc.viewControllers.lastObject];
                          else
                              return vc;
                  
                      } else if ([vc isKindOfClass:[UINavigationController class]]) {
                  
                          // Return top view
                          UINavigationController* svc = (UINavigationController*) vc;
                          if (svc.viewControllers.count > 0)
                              return [UIViewController findBestViewController:svc.topViewController];
                          else
                              return vc;
                  
                      } else if ([vc isKindOfClass:[UITabBarController class]]) {
                  
                          // Return visible view
                          UITabBarController* svc = (UITabBarController*) vc;
                          if (svc.viewControllers.count > 0)
                              return [UIViewController findBestViewController:svc.selectedViewController];
                          else
                              return vc;
                  
                      } else {
                  
                          // Unknown view controller type, return last child view controller
                          return vc;
                  
                      }
                  
                  }
                  
                  +(UIViewController*) currentViewController {
                  
                      // Find best view controller
                      UIViewController* viewController = [UIApplication sharedApplication].keyWindow.rootViewController;
                      return [UIViewController findBestViewController:viewController];
                  
                  }
                  
                  @end
                  

                  然后,每当我需要应用程序中任何地方的当前视图控制器时,只需使用:

                  Then whenever I need the current view controller from anywhere in the app simply use:

                  [UIViewController currentViewController]
                  

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

                  上一篇:self.delegate = 自我;这样做有什么问题? 下一篇:CollectionView 的 NSFetchedResultsContollerDelegate

                  相关文章

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

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

                      <legend id='OttQj'><style id='OttQj'><dir id='OttQj'><q id='OttQj'></q></dir></style></legend>
                      <tfoot id='OttQj'></tfoot>