zoukankan      html  css  js  c++  java
  • [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")
    

      

  • 相关阅读:
    高精度A+B
    基本定积分求面积
    二进制算子集和
    linux命令
    Dubbo
    java 集合区别
    Java中Comparable和Comparator区别
    synchronized实现原理
    ThreadLocal 原理
    java volatile关键字
  • 原文地址:https://www.cnblogs.com/helloandroid/p/4287671.html
Copyright © 2011-2022 走看看