views:

454

answers:

4

I have a custom UIViewController, which is the only subView of UIView. The UIViewController contains delegate function:

  • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; }

This function is called once when the application starts and is never called again when the device is rotated. I also notice that the willRotateToInterfaceOrientation function is never called. I pretty much commented out all the content in the UIViewController but it is still not responding to device rotation.

A: 

You may need to implement that method in the controller of the parent UIView, as it seems your view is enclosed in another view.

Macmade
Thanks. This is not the case.
Wayne Lo
+1  A: 

Your code looks correct. I suspect it's something in your .xib file (like the wrong object type for "File's Owner"), so that perhaps your view controller subclass isn't being instantiated at all. Put some logging into viewDidLoad and make sure it's getting called.

Frank Schmitt
Your answer is really close. Normally it is easy to find out a UIViewController was not properly instantiated because nothing will work in the first place. My case is a little trickier. Please view my answer to my own question.
Wayne Lo
+1  A: 

Try doing a test app that just tests the rotation problem. This will help isolate your issue.

Hua-Ying
I did take your approach and isolated the problem. Thanks.
Wayne Lo
+2  A: 

I ended up solving my own problem by starting from stretch to create a brand new UIViewController and made sure it was responsive to the device rotation. I then brought in my code piece by piece and checked the rotation. In the end, I found the root cause. In my custom UIViewController, I had

- (id)initWithFrame:(CGRect)theframe {
    if (self.view = [super.view initWithFrame:theframe])

It worked find excpet it did not respond to device roation even though I did not call the init function. The solution is simple. Add [self init] in the initWithFrame function. Thank you all for responding.

Wayne Lo