如何知道当前正在查看什么视图

发布于 2024-12-14 16:27:14 字数 1151 浏览 4 评论 0原文

我正在开发一个项目,在该项目中我呈现一个值表,当用户旋转屏幕景观时,会以图表形式显示详细信息。

到目前为止,一切正常,但有一个问题。例如,当我从 LandscapeLeft 海峡转到 LandscapeRight 时,它会再次推动视图。显然我不希望这种情况发生。

这是我使用的代码:

    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

if (orientation == UIDeviceOrientationLandscapeLeft)
{
    NSLog(@"Landscape Left!");
    GraphViewController *gvc = [[GraphViewController alloc] initWithNibName:@"GraphViewController" bundle:nil];

        [self.navigationController pushViewController:gvc animated:YES];
        strg.orient = [[NSNumber alloc] initWithInt:1];
}
if (orientation == UIDeviceOrientationLandscapeRight)
{
    NSLog(@"Landscape Right!");
    GraphViewController *gvc = [[GraphViewController alloc] initWithNibName:@"GraphViewController" bundle:nil];

        [self.navigationController pushViewController:gvc animated:YES];
        strg.orient = [[NSNumber alloc] initWithInt:2];
}
if (orientation == UIDeviceOrientationPortrait)
{
    NSLog(@"Portrate!");

    [self.navigationController popViewControllerAnimated:YES];
}   

我的问题是如何知道视图是否已被查看,以便我可以告诉 NavigationController 不要推送它?

谢谢分配!

i'm working on a project in which i present a table of values, and when the user rotates the screen landscape is shows the detail as a graph.

so far it all works, but there is a problem. When I go from LandscapeLeft strait to landscapeRight for example, it pushes the view again. Obviously I don't want this to happen.

Here is the code i used:

    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

if (orientation == UIDeviceOrientationLandscapeLeft)
{
    NSLog(@"Landscape Left!");
    GraphViewController *gvc = [[GraphViewController alloc] initWithNibName:@"GraphViewController" bundle:nil];

        [self.navigationController pushViewController:gvc animated:YES];
        strg.orient = [[NSNumber alloc] initWithInt:1];
}
if (orientation == UIDeviceOrientationLandscapeRight)
{
    NSLog(@"Landscape Right!");
    GraphViewController *gvc = [[GraphViewController alloc] initWithNibName:@"GraphViewController" bundle:nil];

        [self.navigationController pushViewController:gvc animated:YES];
        strg.orient = [[NSNumber alloc] initWithInt:2];
}
if (orientation == UIDeviceOrientationPortrait)
{
    NSLog(@"Portrate!");

    [self.navigationController popViewControllerAnimated:YES];
}   

My question is how can I know if the view is already viewed, so I can tell the NavigationController to not push it?

Thanks allot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文