2016-02-20 46 views
0

我正面臨一個我將要描述並發現一些類似問題的問題,但我不相信與我的問題有關。如何正確解僱提出的ViewController並返回到父ViewController?

我有一個UITabBarController與2個選項卡VC1和VC2。 VC1繼續到VC4。 VC2繼續到VC3,VC3繼續到VC4。 VC4包含MPMoviePlayerViewController例如,爲如下所示:

   - - - - - -> VC1 \ 
TAB BAR VC/     - - -> VC4 
      \     /
      -> VC2 -> VC3 ->/

我有聽當視頻完成一個通知,並解僱VC4,並返回到哪個父VC提出VC4,也就是說,如果VC1呈現VC4,然後在解僱VC4後,應該回到VC1。同樣,如果VC3提供了VC4,那麼在解除VC4後,應該返回到VC3。

在VC4:

override func viewDidLoad() 
{ 
    NSNotificationCenter.defaultCenter().addObserver(
     self, 
     selector: "moviePlayerPlayBackDidFinish:", 
     name: MPMoviePlayerPlaybackDidFinishNotification, 
     object: player?.moviePlayer) 
} 

func moviePlayerPlayBackDidFinish(notification: NSNotification) 
{ 
    NSNotificationCenter.defaultCenter().removeObserver(
     self, 
     name: MPMoviePlayerPlaybackDidFinishNotification, 
     object: notification.object 
    ) 

    player!.view.removeFromSuperview() 

    self.presentedViewController?.dismissViewControllerAnimated(true, completion: nil) 
} 

我不認爲我正在使用的代碼在VC4正確,因爲self.presentedViewController?.dismissViewControllerAnimated(true, completion: nil)住宿。

我發現了一些類似的問題:

  1. How to dismiss the current ViewController and go to another View in Swift
  2. How to dismiss VIewController iOS Swift
  3. modal View controllers - how to display and dismiss

然而,序列塞格斯是不同的,因此,我不能按照建議。

我該如何做到這一點?由於

UPDATE:

moviePlayerPlayBackDidFinish下面的代碼,如果從VC1要妥善遣散VC4,回到父母VC1 - > VC4:

self.dismissViewControllerAnimated(true, completion: nil); 

然而,VC4不會去當解僱VC3→VC4。

+0

大約只是'self.dismissViewControllerAnimated(真,完成什麼:無)'? – yesthisisjoe

+0

問題已經更新 – Pangu

+0

我猜測沒有工作 – yesthisisjoe

回答

相關問題