0

So I have a view that I present modally when the interface orientation changes to landscape. However when the orientation returns to portrait and the modal view dismisses itself, the tableview from the initial view remains in landscape orientation (this table view must be only in portrait orientation)

Here is the code :

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return ((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight) );
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if ((toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)) {
        [self performSegueWithIdentifier:@"showCatChart" sender:self];
    }
    if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
        [self refreshTableView];
    }
}

I tried to refresh the tableview but that doesn't make it portrait again ... this could be from the view hierachy ... NavigationController->tableView (only portrait)->tableview->landscapeViewModalController

4

2 回答 2

0

在 iOS 6 中,您需要实现以下内容:

- (BOOL)shouldAutoRotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

在您的 AppDelegate 中,您需要更改以下内容:

[self.window addSubview:viewController.view];

[self.window setRootViewController:viewController];

此外,如果您想支持以前版本的 iOS,请保留您当前的代码。

于 2012-11-14T13:39:20.997 回答
0

在 appdelegate 中使用以下内容。

[self.window addsubview:viewcontroller];

仅此一项就可以解决您的方向问题。

于 2012-11-13T17:56:50.963 回答