2017-04-08 108 views
2

我正在使用頁面視圖控制器在我的應用中實現圖像輪播。我有一個容器視圖在我的父視圖控制器中有一個嵌入頁面視圖控制器。我遇到的問題是當我需要離開並異步獲取這些圖像,並且在viewDidLoad獲取圖像之前發生了繼續。Programmatic embed segue

我的賽格瑞準備:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if segue.identifier == "startCarousel" { 
    let carouselPageViewController = segue.destination as! CarouselPageViewController 
    carouselPageViewController.images = carouselImages 
    } 
} 

在viewDidLoad中:

GalleryManager.sharedInstance.getData = { 
    (data) in 
    // Assign images to instance property here ...  
} 

我的想法是,一旦我得到一些編程方式啓動SEGUE自己的圖像。或者,如果我應該以不同的方式來做這個任何建議,我們將非常感激。

+2

獲取的圖像中嵌入視圖控制器,而不是嵌入式視圖控制器,或者保留對嵌入式視圖控制器的引用,並在擁有它們後更新圖像屬性。 – Paulw11

+0

我同意@ Paulw11或者你可以在viewWillAppear或viewDidAppear中移動getData函數,因此函數在加載圖像時不會造成延遲。 –

回答

2

不,你不能延遲嵌入segue。如果您使用嵌入式segue,只要裝入視圖控制器就會觸發。

您需要等待數據加載完畢,然後調用setViewControllers(direction:animated:completion)來安裝視圖控制器,一旦數據加載後您將使用這些視圖控制器來顯示數據。

0

你不能延遲嵌入segue。

你試圖把按鈕在視圖控制器,然後後視圖負載設定按鈕,點擊設置圖像...

1

斯威夫特3,Xcode中8

您可以用這種方式實現:

  1. 設置在masterViewController在prepareForSegue到你的頁面視圖控制器的引用:

    var myContainerViewController: UIPageViewController? 
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) 
    { 
        if segue.identifier == "embedSegue" { 
        if let destination = segue.destination as? YourPageViewControllerClass { 
         self.myContainerViewController = destination 
        } 
    } 
    
  2. 在自己的pageViewController類中定義的函數:

    func someFunction(){ 
        //configure your image or swipe page 
    } 
    
  3. 當你得到的圖像,在您的masterViewController電話:

    self.myContainerViewController?.someFunction()