无法在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
不是一个选项…
谢谢
你可以试试这个 –
-
使一个
AppDelegate
currentModelViewController
(即currentModelViewController
)@property (nonatomic, retain) UIViewController *currentModelViewController;
-
对于
viewDidAppear
或viewWillAppear
每个ViewController
appDelegate = [[UIApplication sharedApplication] delegate]; appDelegate.currentModelViewController = self;
现在这将工作
if ([self.currentModelViewController isKindOfClass:[LowProfileViewController class]]) { NSLog(@"here!"); }