0
votes

I have a class which is subclass of tableViewController. I am trying to rotate my table view. I implemented two methods :

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == (UIInterfaceOrientationPortrait | UIInterfaceOrientationLandscapeLeft |
                                     UIDeviceOrientationLandscapeRight));
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    [self.tableView reloadData];
}

This controller is named as rootViewController and part of appDelegate's method didFinishLaunchingWithOptions: is

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.rootViewController];
self.navigationController = navController;
self.window.rootViewController = self.navigationController;

where I have set rootViewController as navigationController and its rootViewController as my rootViewController object.

I dunno if the two methods are sufficient to reload the table according to the orientation. Do I have to include any other methods? And I saw that (void)didRotateFromInterfaceOrientation: of my rootViewController is not called after rotation but shouldAutorotateToInterfaceOrientation: is called often even when it is not required. I saw a similar post and there they suggested to include [super didRotateFromInterfaceOrientation: interfaceOrientation] but still it didn't work.

1
are you using iOS6? The methods you're mentioning are from <= iOS5. There's a new model for rotation in 6 and above and you need to implement both if you want backwards compatibility. - Cocoadelica
ah then you might want to remove the iphone-5 tag from your question as it only runs iOS6 and above and might cause confusion. - Cocoadelica
also whats the larger project set to do with orientation? - Cocoadelica
basically there is a set of servers listed in table view. When the orientation changes from portrait to landscape I need it to change the table view accordingly. should we manually change the table view height and width or if we reload will the controller change according to the window? - aparna
no, no need to manually change things. In Xcode, if you click on the project in the left hand section, then select the targets Summary, look for what the supported interface orientations are. - Cocoadelica

1 Answers

0
votes

no you shouldn't need to manually change anything. Question: is the tableView set as the view for the enclosing viewController?