0

我想显示图像以响应iPhone锁定时发生的本地通知事件。当用户在通知上滑动时,我希望我的应用程序通过popToViewController进入根视图控制器:animated,然后推送显示图像的视图控制器。这适用于我设置动画= YES。当animated = NO时,显示图像的视图控制器在用户点击后退按钮时不响应。任何想法为什么图像视图控制器的导航控件不起作用时,我popToViewController没有动画?提前致谢。如何在没有动画的情况下弹出到视图控制器

下面是相关的代码...

- (void) localNotificationHandler 
{ 
#ifdef kAnimatePop 
    animated = YES; // This works 
#else 
    animated = NO;  // This doesn't work 
#endif 
    _showImage = YES; 

    // Check if this view controller is not visible 
    if (self.navigationController.visibleViewController != self) { 
     // Check if there are view controllers on the stack 
     if ([self.navigationController.viewControllers count] > 1) { 
      // Make this view controller visible 
      [self.navigationController popToViewController:self animated:animated]; 
     } 
    } 
}  


- (void) viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 
    if (_showImage) { 
     _showImage = NO; 
     // Show image in a view controller 
     [self performSegueWithIdentifier:@"MainToImageSegue" sender:self]; 
    } 
} 

回答

1

您没有设置_showImage直到popToViewController已被调用后。如果它的动画viewDidAppear将不会被调用,直到后来,所以它意外的作品。如果未设置动画,则在设置_showImage之前立即调用viewDidAppear。将_showImage = true;移至导航控制器堆栈操作之前。

+0

感谢您的回答,但这不会导致问题。我会编辑我的代码以避免混淆。 – 0x141E

0

我可能做的检查是这样的:

- (void) localNotificationHandler{ 
... 

... 
    if (self.navigationController.topViewController != self) { 
     [self.navigationController popToRootViewControllerAnimated:NO]; 
    } 
}  

我也建议的东西推你的图像视图控制器编程像

[self.navigationController pushViewController:<imageVC> animated:YES]; 

如果图像视图控制器的导航按钮不起作用,很可能是因为它将这些导航消息发送到nil。也就是说,imageViewControllers self.navigationController等于nil。 我不知道如何解决这个故事板,但如果你以编程方式提出该问题应该消失。

+0

如果正在显示模态VC,则根VC可以是topViewController,但不可见。我不确定手动推送VC和使用segue方法是否有区别。顺便说一句,navigationController不是零。感谢你的回答。 – 0x141E

相关问题