无法在applicationWillResignActive中获取当前ViewController

我有一个基于故事板的单一视图应用程序;

我的故事ViewControllers有3个ViewControllers链接到代码中的3个ViewController类;

我通过这样浏览ViewControllers之间:

 UIStoryboard* sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]]; MenuViewController* mainMenu = [sb instantiateViewControllerWithIdentifier:@"vcMainMenu"]; mainMenu.modalTransitionStyle = UIModalTransitionStyleCoverVertical; [self presentModalViewController:mainMenu animated:YES]; 

现在我需要从当前活动的ViewController访问UIcontrols上的不同的UIcontrols ,我将访问取决于ViewController不同的控件,我试图做到这一点:

 if ([self.window.rootViewController isKindOfClass:[LowProfileViewController class]]) { NSLog(@"here!"); } 

但是它总是返回rootViewController 。 如何从applicationWillResignActive获取当前显示的rootViewController

请结合NavigationController不是一个选项…

谢谢

你可以试试这个 –

  1. 使一个AppDelegate currentModelViewController (即currentModelViewController

     @property (nonatomic, retain) UIViewController *currentModelViewController; 
  2. 对于viewDidAppearviewWillAppear每个ViewController

     appDelegate = [[UIApplication sharedApplication] delegate]; appDelegate.currentModelViewController = self; 

现在这将工作

 if ([self.currentModelViewController isKindOfClass:[LowProfileViewController class]]) { NSLog(@"here!"); }