CollectionView控制器创建没有故事板

时间:2016-03-09 11:53:15

标签: ios swift controller collectionview

大家好我是Swift的新手,目前我仍然坚持以下问题。 当在表视图控制器上选择一行时,它会推送一个集合视图控制器,但是我收到此错误:

UICollectionView must be initialized with a non-nil layout parameter.

在tableview控制器

上选择行时出现错误
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'UICollectionView must be initialized with a non-nil layout parameter'

请问这个指针吗?

App Delegate:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    window = UIWindow(frame: UIScreen.mainScreen().bounds)
    window?.makeKeyAndVisible()

    window?.rootViewController = CustomTabBarController()

    return true
}
当选择行时,

选项卡栏控制器已使用表视图控制器初始化它应该推送到集合视图控制器

集合视图单元格已在viewDidLoad中注册:

collectionView?.registerClass(PostCell.self, forCellWithReuseIdentifier: CELLID)

1 个答案:

答案 0 :(得分:2)

终于解决了。在Collection视图中,控制器使用以下方法初始化

<div class="col-md-12">
                        <div class="row">
                            <div class="col-md-4 accesories-box-main">
                                <div class="row">
                                    <div style="background-image: url('content/images/accesories/accesories-hook.png');" class="col-md-12 accesories-box">
                                        <h2>Heading</h2>
                                        <p class="accesories-price" style="padding-top: 40px; padding-left: 20px;">

                                     420 
                                        </p>
                                    </div>
                                    <div class="col-md-12 acccesories-description">
                                        <p>
                                            It also falls back to a solid color background if CSS gradients are not supported. It will work on Firefox 3.6+, Chrome, Safari, Opera 11.10+ and IE10+.
                                            PS: For my twitter friends, I had already written this when the robbers came and I was about to post it. I might have been really calm, but not as much as making CSS experiments the same day I was robbed and threatened by a gun
                                        </p>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-4 accesories-box-main">
                                <div class="row">
                                    <div style="background-image: url('content/images/accesories/accesories-roof.png');" class="col-md-12 accesories-box">
                                        <h2>Heading</h2>
                                        <p class="accesories-price">
                                         420 
                                        </p>
                                    </div>
                                    <div class="col-md-12 acccesories-description">
                                        <p>
                                            It also falls back to a solid color background if CSS gradients are not supported. It will work on Firefox 3.6+, Chrome, Safari, Opera 11.10+ and IE10+.
                                            PS: For my twitter friends, I had already written this when the robbers came and I was about to post it. I might have been really calm, but not as much as making CSS experiments the same day I was robbed and threatened by a gun
                                        </p>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-4 accesories-box-main">
                                <div class="row">
                                    <div style="background-image: url('content/images/accesories/accesories-roof.png');" class="col-md-12 accesories-box">
                                        <h2>Heading</h2>
                                        <p class="accesories-price">
                                           420 
                                        </p>
                                    </div>
                                    <div class="col-md-12 acccesories-description">
                                        <p>
                                            It also falls back to a solid color background if CSS gradients are not supported. It will work on Firefox 3.6+, Chrome, Safari, Opera 11.10+ and IE10+.
                                            PS: For my twitter friends, I had already written this when the robbers came and I was about to post it. I might have been really calm, but not as much as making CSS experiments the same day I was robbed and threatened by a gun
                                        </p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

同时推动视图控制器         让flowLayout = UICollectionViewFlowLayout()         让newPostCollection = TestCVC(collectionViewLayout:flowLayout)

谢谢大家