views:

445

answers:

2

I am using this code in the DetailView.m of a splitview app. Now the orientation changes occur only when the device is rotated. The detection does not take place when the app is launched. I also get this warning

warning: 'RootViewController' may not respond to '-adjustViewsForOrientation:'

What change do I need to make the app adjust the orientation code when the app is launched.

> - (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
> duration:(NSTimeInterval)duration {
>     [self adjustViewsForOrientation:toInterfaceOrientation];
> }
> 
> - (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation
> {
>     if (orientation == UIInterfaceOrientationLandscapeLeft ||
> orientation ==
> UIInterfaceOrientationLandscapeRight)
> {
>         detailDescriptionLabel.center = CGPointMake(235.0f, 42.0f);
>         bigthumbImageView.center = CGPointMake(355.0f, 70.0f);
>         
>     }
>     else if (orientation == UIInterfaceOrientationPortrait ||
> orientation ==
> UIInterfaceOrientationPortraitUpsideDown)
> {
>         detailDescriptionLabel.center = CGPointMake(160.0f, 52.0f);
>         bigthumbImageView.center = CGPointMake(275.0f, 80.0f);
>         
>     } }
A: 

You need to declare your method in RootViewController.h, like so:

- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation;

Otherwise you'll get the warning. To make sure your view rotates when the app launches, add a call to adjustViewsForOrientation in your AppDelegate class in the applicationDidFinishLaunching method.

pheelicks
Thanks. This removed the warning.
nishantcm
A: 

To remove the warning, move the definition of -adjustViewsForOrientation: before -willRotateToInterfaceOrientation:….

The -willRotateToInterfaceOrientation:… method will only be called when there's an interface rotation. When the app was first launched, the interface doesn't rotate (it follows the initial orientation), so this call is not generated. You have to call it manually, e.g. in -viewDidLoad:

-(void)viewDidLoad {
   [self adjustViewsForOrientation:self.interfaceOrientation];
}
KennyTM
This did the trick although the answer by pheelicks removed the warning. Thanks
nishantcm