无法在applicationWillResignActive中获取当前ViewController [英] Not able to get Current ViewController inside applicationWillResignActive
问题描述
我有一个基于故事板的Single View应用程序;
I have a storyboard based Single View App;
我有3个 ViewControllers
ViewController
代码中的类;
I have 3 ViewControllers
on my Storyboard linked to 3 ViewController
classes in the code;
我在 ViewControllers之间浏览
通过这样做:
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
MenuViewController* mainMenu = [sb instantiateViewControllerWithIdentifier:@"vcMainMenu"];
mainMenu.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:mainMenu animated:YES];
现在我需要访问不同的 UIcontrols
来自当前活动 ViewController
的 applicationWillResignActive
,我将根据 ViewController
,我试图这样做:
Now I need to access different UIcontrols
on the applicationWillResignActive
from the current active ViewController
, I will access different controls depending of the ViewController
, I'm trying to accomplish this by doing:
if ([self.window.rootViewController isKindOfClass:[LowProfileViewController class]])
{
NSLog(@"here!");
}
但它总是返回 rootViewController
。如何获取当前显示 rootViewController 从
applicationWillResignActive
?
But it always returns the rootViewController
. How Can I get the current displayed rootViewController
from applicationWillResignActive
?
请,并入 NavigationController
不是一个选项...
Please, Incorporate NavigationController
is not an option...
感谢
推荐答案
您可以试试这个 -
You could try this -
-
code> AppDelegate
@property
(即currentModelViewController
)
@property (nonatomic, retain) UIViewController *currentModelViewController;
对于每个 ViewController
viewDidAppear
或在 viewWillAppear
appDelegate = [[UIApplication sharedApplication] delegate];
appDelegate.currentModelViewController = self;
b
$ b
Now this will work
if ([self.currentModelViewController isKindOfClass:[LowProfileViewController class]])
{
NSLog(@"here!");
}
这篇关于无法在applicationWillResignActive中获取当前ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!