2017-07-12 3 views
0

MainViewControllerがあり、その内部にコンテナビューがあり、UIPageViewControllerが埋め込まれています。 MainViewControllerUIPageViewControllerDelegate, UIPageViewControllerDataSource のプロトコルに準拠しており、によって埋め込まれたUIPageViewControllerを埋め込みたいとします。 それも可能ですか?ViewControllerに埋め込まれたコンテナビュー内のUIPageViewControllerのデリゲートを設定する方法

基本的に私は、ストーリーボードのアウトレットとしてビューコントローラ内にコレクションビューを持ち、それをデリゲートするような態度を取ろうとしています(collectionView.delegate = self、自己委任と仮定します) この態度はUIPageViewController。 私が遭遇した障害物がコレクションビューに比較PageViewController(へopposodeとして何PageViewがないことですが、私はCollectionViewControllerとは対照的に、CollectionViewを持って

enter image description here

答えて

1
ここ

あなたがこれを生成するために使用できる手順は次のとおりです。

あなたの組込コントローラが子行われたとき、この機能がトリガされる。MainViewControllerでfunc prepare(for segue: UIStoryboardSegue, sender: Any?)をオーバーライドすることによって、あなたのUIPageViewControllerへの参照を取得することができます。

func prepare(for segue: UIStoryboardSegue, sender: Any?) { 

    if segue.identifier == "pageSegue", let controller = segue.destination as? UIPageViewController { 
     controller.delegate = self 
     controller.dataSource = self 
    } 

} 
+0

素晴らしい仕事!あなたのセグエに名前(のは、この例ではpageSegueを使用してみましょう)、あなたはMainViewControllerにこのような何かを行うことができますを与え考える – Eyzuky

関連する問題