ios - 当单击推送通知以及应用程序也在后台时,ViewController 丢失了引用
问题描述
- 应用程序在后台
- 推送通知被接收并点击
- 应用程序将打开并重定向到 SecondViewController 并单击后退按钮
- 当从 SecondViewController 单击返回按钮并返回到 FirstViewController 时,“菜单”会丢失来自 MenuViewController 的引用
- 推送通知被接收并点击
- 应用程序将打开并重定向到 SecondViewController 并单击后退按钮
- 当从 SecondViewController 单击返回按钮并返回到 FirstViewController 时,“菜单”会丢失来自 MenuViewController 的引用
我的代码:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
if (application.applicationState == UIApplicationStateActive) {
.......
} else {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UINavigationController *navigationController=[[UINavigationController alloc] init];
self.window.rootViewController = nil;
self.window.rootViewController = navigationController;
MenuViewController *menuViewController = [storyboard instantiateViewControllerWithIdentifier:@"MenuViewController"];
[navigationController pushViewController:menuViewController animated:NO];
HomeViewController *homeViewController = [storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
[navigationController pushViewController:homeViewController animated:NO];
AllNewsNotificationViewController *allNewsNotificationViewController = [storyboard instantiateViewControllerWithIdentifier:@"AllNewsNotificationViewController"];
[navigationController pushViewController:allNewsNotificationViewController animated:YES];
[self.window makeKeyAndVisible];
}
我的 MenuViewController 实现:
@implementation MenuViewController
- (id)init {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
self = [storyboard instantiateViewControllerWithIdentifier:@"MenuViewController"];
if (!self) {
return self;
}
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.homeViewController];
NSDictionary *options = @{
PKRevealControllerRecognizesPanningOnFrontViewKey : @YES,
PKRevealControllerDisablesFrontViewInteractionKey : @NO
};
self.revealController = [SubviewPKRevealViewController revealControllerWithFrontViewController:self.navigationController leftViewController:self options:options];
self.revealController.revealDelegate = self.homeViewController;
// The target view controller must implement this method
self.navBarGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self.homeViewController action:@selector(menuPan:)];
[self.navigationController.navigationBar addGestureRecognizer:self.navBarGesture];
self.view.backgroundColor = [[Configurations sharedInstance] menuBackgroundColor];
_topView.backgroundColor = [[Configurations sharedInstance] navegationbarBackgroundColor];
return self;
}
MenuViewController 中的菜单快捷方式(按钮)丢失了引用并且不起作用。
解决方案
推荐阅读
- ios - 图像的打印尺寸 - 错误:“尺寸”的使用不明确
- android - proguard AssembleRelease 错误
- python - 我想对列名进行分组并将它们的值添加到 df
- java - 部署到 Tomcat 服务器时包含 spring-boot-starter-tomcat 会出现什么问题?
- python - 在 Numba 中创建日期数组?
- python - 在 for in 循环期间附加到元组
- java - zip/gzip 文件的奇怪问题
- java - 尝试从 Google Analytics API 中提取受众数据
- python-3.x - 在python中多次调用classmethod
- python-3.x - PySpark如何高效处理嵌套数据?