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

相關問題