views:

179

answers:

2

Simple iPad app.

App loads and displays a UITableView controlled by a subclass of UIViewController. This works and rotates perfectly.

Clicking on a row in the table view causes a new subview to be created, also controlled by a UIViewController subclass. This displays fine in portrait but does not adjust to landscape and does not respond to device rotation.

Both of the view controllers have inlcuded:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    NSLog(@"Responding to rotation");
    return YES;
}

However only the original view controller responds to this:

   - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    NSLog(@"View About to rotate");
}

In IB I have checked that the view will autoresize and the components within it (a UIScrollView and some UILabels) will adjust properly.

Can anyone help me in working out why the subview isn't responding.?

A: 

Not sure, but AFAIK only one UIViewController is active at a time (in terms of receiving events from UIKit). Is your second view controller pushed via -presentModalViewController:animated: ? If not, you might need to proxy the -willRotateToInterfaceOrientation: method (and maybe others as well) from the one that does receive the events to the other one.

DarkDust
the second view controller is loaded by [self.view.window addSubview:detailVC.view];[self.view.window bringSubviewToFront:detailVC.view];
MightyLeader
do you think I'm wrong to use a second view controller for the loaded subview? Should I just create it programitically and load it as a view and control both from the same root view controller?
MightyLeader
+2  A: 

I found the answer from a friend of mine...

I was adding the subview to the view by using

[mainView.view.window addSubview detailView.view];

However this was adding it to the window not the view and since the window only passes rotation events along to one view controller I was putting my subview in the wrong place. Instead I changes it to...

[mainView.view addSubview detailView.view];

Which works! Just need to add code for resizing the subview upon rotation and it's done.

Look here for further info: http://developer.apple.com/iphone/library/qa/qa2010/qa1688.html

MightyLeader