UIViewController auto rotate not working

I have found quite a lot on this subject but I just can't figure it out. Any help would be massively appreciated!

I have an app set up with a UITabBarController. Within one of the tabs, I am showing a UITableView which is using a UINavigationController to allow for hierarchy. All the tables rotate just fine when the orientation is changed, until I get to what is effectively the final view in the hierarchy.

The final view is not a UITableView, just a basic UIView. But I can not get this page to rotate successfully! I have remade the view from with the absolute basics required and it still doesn't want to work! The code is below but it is currently pretty much a standard template with nothing in it now.

Also, I am not using InterfaceBuilder, and shouldAutorotateToInterfaceOrientation is on all views. This is the only one I am having problems with.

SomeView.h

#import <UIKit/UIKit.h>
@interface SomeView : UIViewController
{
    NSString *someID;
    NSString *someName;
}
@property(nonatomic,retain) NSString *someID;
@property(nonatomic,retain) NSString *someName;
@end

SomeView.m

#import "SomeView.h"
#import "AppDelegate.h"
@implementation SomeView
@synthesize someID, someName;

-(void)loadView
{
}

-(void)viewDidLoad
{
    [super viewDidLoad];
}

-(void)viewDidUnload
{
    [super viewDidUnload];
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return YES;
}

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
    NSLog(@"willAnimateRotationToInterfaceOrientation");
}

-(void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

-(void)dealloc
{
    [super dealloc];
}
@end

UPDATE 10th Nov 2011

I'm still having this issue, however looking through documents and bits this seems to be my problem (http://developer.apple.com/library/ios/#qa/qa1688/_index.html)

The view controller's UIView property is embedded inside UIWindow but alongside an additional view controller.

You may find a situation where shouldAutorotateToInterfaceOrientation is called once at startup for a given view controller but is never called again when the device is rotated. Because view controllers are tightly bound to the views they manage, they are also part of the responder chain used to handle events. View controllers are themselves descendants of the UIResponder class and are inserted into the responder chain between the managed view and its superview. So it is common practice to have one primary view controller in your application as part of the responder chain. You would typically add one primary view controller such as a UINavigationController, UITabBarController or a generic UIViewController to your UIWindow. For example, this is done by calling:

[myWindow addSubview:primaryViewController.view];

If you add an additional view controller's UIView property to UIWindow (at the same level as your primary view controller) via the following:

[myWindow addSubview:anotherController.view];

this additional view controller will not receive rotation events and will never rotate. Only the first view controller added to UIWindow will rotate.


My UITabBarController stopped to autorotate, when I added a new navigationController to it with a tableViewController and didn't notice, that my custom navigation controller's shouldAutorotateToInterfaceOrientation returns YES only for one orientation. The solution is to check shouldAutorotateToInterfaceOrientation function in each Controller inside TabBarController.

May be it will help to somebody.


我已经想通了......我正在查看将UIViewController推入堆栈的代码,并且我没有完全启动UIViewController。

链接地址: http://www.djcxy.com/p/54966.html

上一篇: 容器控制器和iOS 6旋转

下一篇: UIViewController自动旋转不起作用