简体   繁体   English

如何将CollectionView作为子视图添加到ViewController

[英]How to add collectionview as subview to viewcontroller

i had a little problem with my collectionview when i want to add it as a subview to my ProfileViewController. 当我想将它作为子视图添加到我的ProfileViewController时,我的collectionview遇到了一个小问题。 The problem occurred when i want to reload the collectionview and xcode give me an error property 'collectionview' not found on object of type ProfileViewController . 当我想重新加载collectionview并且xcode给我一个在ProfileViewController类型的对象上找不到的错误属性'collectionview'时,发生了问题 how can i overcome this problem? 我该如何克服这个问题? do i to create a new collectionview class file and set it to collectionview on ProfileViewController ? 我要创建一个新的collectionview类文件并将其设置为ProfileViewController上的collectionview吗? Below is the image for my storyboard. 下面是我的情节提要的图像。

the image for storyboard is at this link. 情节提要的图像位于此链接。 http://i.stack.imgur.com/XSE29.png . http://i.stack.imgur.com/XSE29.png I can't attached an image to this post cause my reputation is low. 由于我的声誉低,我无法在该帖子上附加图片。

You'll want make sure your ProfileViewController conforms to the UICollectionViewDataSource and UICollectionViewDelegate protocols and when you create the collection view inside the ProfileViewController make sure you do: 您将要确保您的ProfileViewController符合UICollectionViewDataSource和UICollectionViewDelegate协议,并且在ProfileViewController中创建集合视图时,请确保执行以下操作:

collectionView.delegate = self;
collectionView.dataSource = self;

Sounds like you're trying to use self.collectionView, where that property doesn't exist on the ProfileViewController. 听起来您正在尝试使用self.collectionView,但该属性在ProfileViewController上不存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM