为什么这段代码没有将collectionviewcontroller的视图设置为可见的?

时间:2014-09-18 01:53:22

标签: ios swift

import UIKit

class CollectionHolderViewController: MainPageContentViewController { //MainPageContentViewController inherits from UIViewController

    var collectionViewController = UICollectionViewController()

    override func viewDidLoad() {
        super.viewDidLoad()
        self.collectionViewController = self.storyboard!.instantiateViewControllerWithIdentifier("TrophyRoom") as UICollectionViewController
        // Do any additional setup after loading the view.

        self.addChildViewController(collectionViewController)
        self.view.addSubview(collectionViewController.view) //I tried collectionViewController.collectionView with no success either
        self.collectionViewController.didMoveToParentViewController(self)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}

此代码适用于UIPageViewController,但不适用于此UICollectionViewController。

我只看到一个空白的白色(默认)UIViewController,如果没有设置UICollectionViewController的视图,这是预期的。 XCode 6中没有显示错误。

帮助?

编辑:代码实际上工作:)只是一个提示,设置collectionViewController.view以使框架填充屏幕以保持一致性,否则它将适合状态栏下方。

0 个答案:

没有答案