首页 文章

UIViewController中的UICollectionView

提问于
浏览
0

我试图在UIViewcontroller中使用UICollectionView并遇到一些问题...不确定我做错了什么?我将故事板中的UICOllectionView设置为dataSource和delegate但仍然出现错误...感谢您提供的所有帮助!

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
        }


    }

1 回答

  • 0

    viewdidLoad 中添加此代码

    collectionView.registerClass(NSClassFromString("YourCellClass"),forCellWithReuseIdentifier:"CELL");
    

相关问题