Search code examples
objective-cios5uiviewcontrolleruiinterfaceorientation

tableView of tableViewController does not change according to its orientation


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.


Solution

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