0

enter image description here需要幫助解僱模態呈現視圖控制器,並從彈出的UINavigationController視圖控制器

的AppDelegate

- (void)applicationWillEnterForeground:(UIApplication *)application { 
    NSLog(@"applicationWillEnterForeground"); 
    [[NSNotificationCenter defaultCenter]postNotificationName:@"applicationWillEnterForeground" object:nil]; 
} 

V1

-(IBAction)uw:(UIStoryboardSegue*)segue{ 
    NSLog(@"Back on V1"); 
} 

V2

-(void)awakeFromNib { 
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(goBackToV1) name:@"applicationWillEnterForeground" object:nil]; 
} 

-(void)goBackToV1 { 
    NSLog(@"goBackToV1"); 
    [self performSegueWithIdentifier:@"uwid" sender:nil]; 
} 

V3 本模態從V2並且沒有代碼。

運行應用程序後,我點擊主頁按鈕,再次打開應用程序,這個觸發通知,並收到V2

什麼V2是應該做的:

  1. 辭退V3。如果V3沒有ViewController子類,那麼它被解僱否則它不是。
  2. V2本身必須從UINavigationController中彈出,但如果V3沒有被解僱但是給出日誌goBackToV1,則它不會彈出。

如果V3我這樣做NSLog(@"%@", [self presentingViewController]);我得到<UINavigationController: 0x13582d800>

我的問題:

  1. 爲什麼V3當沒有視圖控制器子類分配給它被擱置了。
  2. 爲什麼V3在ViewController子類被分配給它時不會被解僱。
  3. 爲什麼performSegueWithIdentifierV2沒有彈出到V1儘管代碼被執行,但它的簡單被忽略。

回答

1

首先檢查,如果你有presentedViewControllerV2,如果你這樣做,然後關閉它,並在完成塊執行SEGUE,否則直接進行SEGUE,

-(void)goBackToV1 { 
    NSLog(@"goBackToV1"); 
    if(self.presentedViewController) { 
     [self dismissViewControllerAnimated:YES completion:^{ 
      [self performSegueWithIdentifier:@"uwid" sender:nil]; 
     }];  
    } else { 
     [self performSegueWithIdentifier:@"uwid" sender:nil]; 
    } 
} 
+0

感謝解決我的問題,請你也可以根據我問的問題解釋一下嗎? –

+0

可能是因爲您沒有關閉V3,因此V2仍然需要位於視圖層次結構中,因爲它是V3的演示視圖控制器 – ogres

+0

但是,爲什麼在自定義視圖控制器類未分配到故事板時V3會自動被解除? –

相關問題