RollRoll
RollRoll

Reputation: 8472

Not able to get Current ViewController inside applicationWillResignActive

I have a storyboard based Single View App;

I have 3 ViewControllers on my Storyboard linked to 3 ViewController classes in the code;

I browse between ViewControllers by doing this:

UIStoryboard*  sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
MenuViewController* mainMenu = [sb instantiateViewControllerWithIdentifier:@"vcMainMenu"];

mainMenu.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:mainMenu animated:YES];

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!");
}

But it always returns the rootViewController. How Can I get the current displayed rootViewController from applicationWillResignActive?

Please, Incorporate NavigationController is not an option...

thanks

Upvotes: 1

Views: 1116

Answers (1)

Warif Akhand Rishi
Warif Akhand Rishi

Reputation: 24248

You could try this -

  1. Make An AppDelegate @property (i.e. currentModelViewController)

    @property (nonatomic, retain) UIViewController *currentModelViewController;
    
  2. For each ViewControllers in viewDidAppear or in viewWillAppear

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

Now this will work

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

Upvotes: 5

Related Questions