首页 > 移动平台 > 详细

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

时间:2015-02-12 12:10:18      阅读:388      评论:0      收藏:0      [点我收藏+]

先新建一个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")

  

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

原文:http://www.cnblogs.com/helloandroid/p/4287671.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!