简体   繁体   English

当应用程序在后台运行时,iOS 7.x上的UINavigationController推送/弹出错误

[英]UINavigationController push / pop bug on iOS 7.x when app is running in the background

I have set up a UINavigationController as rootViewController of my mainWindow. 我已经将UINavigationController设置为mainWindow的rootViewController。

I push and pop viewcontrollers from code (so pushes and pops are not triggered by user interaction). 我从代码中推送和弹出viewcontrollers(因此,推送和弹出不会由用户交互触发)。

When I do it when the applicaiton is in the foreground, everyhting works as it should. 当我在应用程序处于前台时执行此操作时,一切都会按预期进行。

But when I do it when the application is running in the background, not the correct ViewController is shown. 但是当我在后台运行应用程序时执行此操作时,未显示正确的ViewController。

This issue is reproducible only on iOS 7.x . 仅在iOS 7.x上可重现此问题。

A sample project can be found under this link : https://www.dropbox.com/sh/pmxnpgtrjxwehs7/_l3NW4xllf 在此链接下可以找到一个示例项目: https : //www.dropbox.com/sh/pmxnpgtrjxwehs7/_l3NW4xllf

To reproduce the issue, just put the app into the background and wait 12 second and return the app to the foreground : when you navigate using UINavigationBar's back button, not the navigationController's rootView is shown (as it should) : the background is still green, and not yellow (the navigationController's rootViewController's background is yellow). 要重现该问题,只需将应用程序置于后台并等待12秒钟,然后将应用程序返回至前台:当您使用UINavigationBar的后退按钮进行导航时,未显示navigationController的rootView(应如此):背景仍然为绿色,而不是黄色(navigationController的rootViewController的背景是黄色)。

When the app is in the foreground, tapping on the button with the label "aaaaa" does the same navigation but when it's done, the GUI is in correct state. 当应用程序处于前台时,点击带有标签“ aaaaa”的按钮将执行相同的导航,但是完成后,GUI处于正确的状态。

So in brief : This works when the app is in the foreground but does not work when the app is in the background : 简而言之:这在应用程序位于前台时有效,但在应用程序位于后台时无效:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    NSLog(@"pushViewController!");
    [self pushViewController:[[BViewController alloc] init] animated:YES];

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self popToRootViewControllerAnimated:YES];

        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self pushViewController:[[BViewController alloc] init] animated:YES];
        });
    });
});

Do you know how could this issue be solved? 您知道如何解决这个问题吗?

Thanks in advance! 提前致谢!

I've found a solution : I achieve the same navigation animation using the code posted here : stackoverflow.com/questions/9480458/change-animation-transition . 我找到了一个解决方案:我使用此处发布的代码实现了相同的导航动画: stackoverflow.com/questions/9480458/change-animation-transition The problem is not reproducible using that code! 使用该代码无法重现该问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM