実装
import UIKit struct Pages { var viewControllers:[UIViewController] = [] } class PageCollectionViewController: UICollectionViewController { var pages:Pages = Pages(){ didSet { self.collectionView?.reloadData() } } override func viewDidLoad() { super.viewDidLoad() let page1 = UIViewController() page1.view.backgroundColor = UIColor.yellowColor() self.pages.viewControllers.append(page1) let page2 = UIViewController() page2.view.backgroundColor = UIColor.blueColor() self.pages.viewControllers.append(page2) } // MARK: - UICollectionViewDelegate override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return self.pages.viewControllers.count } override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { var cell = collectionView.dequeueReusableCellWithReuseIdentifier("PageCollectionViewCell", forIndexPath: indexPath) as UICollectionViewCell let view = self.pages.viewControllers[indexPath.row].view return cell } }
3. セルにページをaddSubviewする
次の部分を編集して、
indexPathに対応するviewをセルに貼付けましょう。
手順