单击推送通知时以及应用程序也处于后台时,ViewController都丢失了引用

时间:2018-10-25 15:46:58

标签: ios objective-c uinavigationcontroller

  1. 应用处于后台状态
  2. 已收到推送通知并单击
  3. 应用程序将打开并重定向到SecondViewController,然后单击后退按钮
  4. 当单击从SecondViewController返回的按钮并返回FirstViewController时,“菜单”将丢失MenuViewController的引用

  1. 已收到推送通知并单击

enter image description here

  1. 应用程序将打开并重定向到SecondViewController,然后单击后退按钮

enter image description here

  1. 当单击从SecondViewController返回的按钮并返回FirstViewController时,“菜单”将丢失MenuViewController的引用

enter image description here

我的代码:

- (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中的菜单快捷方式(按钮)丢失了引用,因此无效。

0 个答案:

没有答案