[iOS]通过xib定义Cell然后关联UICollectionView


先新建一个View的xib,然后删掉自动生成的View,拖进一个UICollectionCell,再新建一个对应的UIView继承UICollectionCell类。

OK,接下来该连outlet的就连。

设置delegate和dataSource

然后通常我们都要这样,

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{
        
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("PersonalizedSettingsMovieCell", forIndexPath: indexPath) as PersonalizedSettingsMovieCell
        
        return cell
    }

但仅仅是这样是不行的,找不到 PersonalizedSettingsMovieCell 的 Identifier,所以我们要

1.在xib里面设置Cell的Identifier。

2.UICollectionCell要设置

collectionView.registerNib(UINib(nibName: "PersonalizedSettingsMovieCell", bundle: nil), forCellWithReuseIdentifier: "PersonalizedSettingsMovieCell")

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM