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];
    }
}
4

2 回答 2

1

在调用 popToViewController 之前不要设置 _showImage。如果它是动画的 viewDidAppear 直到稍后才会被调用,所以它出乎意料地工作。如果它没有动画,则在设置 _showImage 之前立即调用 viewDidAppear。移动_showImage = true;到导航控制器堆栈操作之前。

于 2014-04-07T22:15:55.890 回答
0

我可能会这样检查:

- (void) localNotificationHandler{
...

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

我还建议以编程方式推送您的图像视图控制器,例如

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

如果您的图像视图控制器的导航按钮不起作用,可能是因为它正在将这些导航消息发送到nil. aka,imageViewControllersself.navigationController等于nil. 我不知道如何用故事板解决这个问题,但如果你以编程方式呈现它,这个问题应该会消失。

于 2014-04-07T23:46:06.937 回答