Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为什么此代码不将collectionviewcontroller的视图设置为可见视图?_Ios_Swift - Fatal编程技术网

Ios 为什么此代码不将collectionviewcontroller的视图设置为可见视图?

Ios 为什么此代码不将collectionviewcontroller的视图设置为可见视图?,ios,swift,Ios,Swift,此代码适用于UIPageViewController,但不适用于此UICollectionViewController 我只看到一个空白的白色默认UIViewController,如果未设置UICollectionViewController的视图,则会出现该默认UIViewController。XCode 6中没有显示错误 帮忙 编辑:代码确实有效:只是一个提示,请将collectionViewController.view设置为具有填充屏幕的框架以保持一致性,否则它将正好位于状态栏下方。您的

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

我只看到一个空白的白色默认UIViewController,如果未设置UICollectionViewController的视图,则会出现该默认UIViewController。XCode 6中没有显示错误

帮忙


编辑:代码确实有效:只是一个提示,请将collectionViewController.view设置为具有填充屏幕的框架以保持一致性,否则它将正好位于状态栏下方。

您的代码对我来说运行良好。您是否尝试记录self.collectionViewController以查看它是否为零?您的评论使我意识到有故事板错误,感谢您抽出时间测试它!
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.
    }
    */

}