Challenge Question


#1

How do I access HeavyViewController’s view from HeavyRotationAppDelegate?

In my (BOOL)application:didFinishLaunchingWithOptions I have signed up to receive notifications for proximity and I have created a method closerToFace: to execute once this notification is received. However, I don’t know how to set the background color of the HeavyViewController’s view from this method.

Any suggestions?


#2

Hi,
in your application:application didFinishLaunchingWithOptions:launchOptions method you should have something like this:

HeavyViewController *hvc = [[[HeavyViewController alloc]init] autorelease];
[[self window] setRootViewController:hvc];
[[self window] makeKeyAndVisible];

so you know that window has the HeavyViewController as a RootViewController and you can get it with:

[[self window] rootViewController];
But that is not enough. You will also need the view of the RootViewController (HeavyViewController) and you can get with:

[[[self window] rootViewController]view]; An with that information you can change the background color for that view like this:


#3

thanks so much Diallo!

I put that code into my method that is called when the message is received and it works perfectly!


#4

You’re welcome.