简体   繁体   中英

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.

I push and pop viewcontrollers from code (so pushes and pops are not triggered by user interaction).

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.

This issue is reproducible only on iOS 7.x .

A sample project can be found under this link : 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).

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.

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 . The problem is not reproducible using that code!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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