首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UICollectionView in a UIViewController

UICollectionView in a UIViewController
EN

Stack Overflow用户
提问于 2015-07-20 00:34:14
回答 1查看 1.1K关注 0票数 0

我试图在UIViewcontroller中使用一个UIViewcontroller,并让一些issues...not确定我做错了什么?我将故事板中的UICOllectionView设置为dataSource和委托,但仍然需要errors...Thanks提供任何帮助!

代码语言:javascript
复制
class AlbumViewController: UIViewController, UICollectionViewDelegate {

    let collectionViewA = UICollectionView()
    let collectionViewAIdentifier = "AlbumCell"

    override func viewDidLoad() {
        super.viewDidLoad()

        // Initialize the collection views, set the desired frames

        collectionViewA.delegate = self
        collectionViewA.dataSource = self


        self.view.addSubview(collectionViewA)



    }


    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        if collectionView == self.collectionViewA {
            let cellA = collectionView.dequeueReusableCellWithReuseIdentifier(collectionViewAIdentifier) as UICollectionViewCell

            // Set up cell
            return cellA
        }



        func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
            if collectionView == self.collectionViewA {
                return 0 // Replace with count of your data for collectionViewA
            }

            return 0 // Replace with count of your data for collectionViewB
        }


    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-20 04:07:18

viewdidLoad中添加此代码

代码语言:javascript
复制
collectionView.registerClass(NSClassFromString("YourCellClass"),forCellWithReuseIdentifier:"CELL");
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31507415

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档