【发布时间】:2014-03-24 09:41:59
【问题描述】:
我已将 UINavigationController 设置为我的 mainWindow 的 rootViewController。
我从代码中推送和弹出视图控制器(因此推送和弹出不会由用户交互触发)。
当我在应用程序处于前台时执行此操作时,一切正常。
但是当我在后台运行应用程序时执行此操作时,不会显示正确的 ViewController。
这个问题只能在 iOS 7.x 上重现。
可以在此链接下找到示例项目:https://www.dropbox.com/sh/pmxnpgtrjxwehs7/_l3NW4xllf
要重现此问题,只需将应用程序置于后台并等待 12 秒,然后将应用程序返回到前台:当您使用 UINavigationBar 的后退按钮导航时,不会显示 navigationController 的 rootView(应该如此):背景是仍然是绿色,而不是黄色(navigationController 的 rootViewController 的背景是黄色的)。
当应用程序处于前台时,点击带有“aaaaa”标签的按钮会执行相同的导航,但完成后,GUI 处于正确状态。
简而言之: 这在应用程序在前台时有效,但在应用程序在后台时无效:
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];
});
});
});
你知道如何解决这个问题吗?
提前致谢!
【问题讨论】:
-
请贴一些代码。
-
在后台执行推送/弹出操作不是一个好主意。应用进入前台时为什么不做呢?
-
我刚刚添加了一个示例项目的链接,该示例项目可以从 Dropbox 以 zip 的形式下载,并且我已经突出显示了可用于重现该错误的代码中最重要的部分。
-
我已经尝试在应用程序处于后台时实现排队导航,并在应用程序返回前台时执行它们,但由于某种原因问题仍然可以重现......我会更新带有该修复的示例代码...
-
只是一个简单的问题,为什么你在 3 秒后推/弹出/推同一个控制器?您确定没有其他方法可以做同样的事情吗?
标签: ios uinavigationcontroller pushviewcontroller poptoviewcontroller