0
votes

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.

2
is SomeView assigned to one of the tabs in your tab bar or is it navigated to by drilling down from one of the other tabs via a navigation controller?Paul Tiarks
There must be a difference between this UIView and another working UIView. Maybe a simple diff could help.ott--
@PaulTiarks The tabbar is the root, someview is got to via drilling down through tableviews in a navigation controller.rich
@ott This is the only UIView, the rest are all UITableViews.rich

2 Answers

1
votes

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.

0
votes

And I have figured it out... I was looking at the code which pushes the UIViewController onto the stack and I had not fully initied the UIViewController.