views:

246

answers:

1

I have an application which have code like:

window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // UIWindow *window;
viewController = [TopicsViewController new]; //TopicsViewController *viewController; //This is a UITableViewController
navigationController = [UINavigationController new]; // UINavigationController *navigationController;
UIImageView *background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];
[self.navigationController.view addSubview:background];
[self.navigationController.view sendSubviewToBack:background];
[navigationController pushViewController:viewController animated:YES];
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];

Basically i am using UINavigationController and then push UITableViewController or sometime a UIViewController. UIViewController contain elements such as UITextView, UIImage, UIScrollView. Problem is i have been trying to make this application respond to iphone rotation e.g. when held in landscape, application should switch to landscape and vice versa, but nothing works so far.

A: 

You need to implement shouldAutorotateToInterfaceOrientation in your UIViewController subclasses. That will work (most of the time).

Paul Lynch
Isn't that like hell lot of code duplication? I will have to implement it in UITableViewController Subclasses, then UIViewController ones.Damn IPhone OS 2.x was easy, quick code...
Shoaibi
It is exactly the same as you should have been doing in 2.x.
Paul Lynch
in 2.x i would just add shouldAutorotatae... to application delegate and return YES, that doesn't work in here...
Shoaibi