Question

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.?

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top