开发者

present modal view on rotate

So I have a UITableViewControler displaying a tableview in portrait mode.

As soon as i rotate the iPhone i want to present a modal view in landscape mode.

In the tableView i use:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

And to handle the present the modal view:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration {
        if((interfaceOrientation == UIInterfaceOrientationLandscapeRight) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft))
        {
            NSLog(@"Push page view");
            PagingViewController *s = [[PagingViewController alloc] initWithNibName:@"PagingView" bundle:nil];
            s.hidesBottomBarWhenPushed = YES;

            [self presentModalViewController:s animated:YES];
            [s release];
        }
}

The modal view i have the following:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation != UIIn开发者_JAVA技巧terfaceOrientationPortraitUpsideDown);
}

And to dismiss the modal view it self, I do:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration {
    if (interfaceOrientation == UIInterfaceOrientationPortrait)
    {
        NSLog(@"Dismiss my self");
        [self.parentViewController dismissModalViewControllerAnimated:YES];
    }
}

Some how this works two times. The third time i rotate the iPhone from Portrait mode to Landscape mode, i get a bad access error.

I cant figure out what gives me the error. Anyone care for a shot?


The simplest way I can think of is to implement -shouldAutorotate... and dismiss the modal view and return NO to abort rotation. Perhaps that will be sufficient to avoid any concurrency issues. If this suggestion isn't to your liking take a look at NSNotificationCenter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜