具有动态和静态单元格的UICollectionView

Dur*_*rim 5 ios uicollectionview uicollectionviewcell

我在IB上创建的collectionView上有一个自定义动态单元格,它将填充数组中的数据.

我想在同一个CollectionView IB上添加一个静态单元格.是否有可能静态单元格位于Collection View的最后一个对象上,无论数据长度是来自动态单元格,静态单元格都将作为最后一个对象添加?

小智 1

这是执行此操作的代码..我尝试了此方法...对于动态单元格和静态单元格...

func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
    return 2
}

// Retuens the number of sections in collectionview
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
    if section == 0 {
    return data.count
    }else if section == 1{
        return 1
    }else {
        return 0
    }
}
// Data get's filled into UICollectionView
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
    var cell : CollectionCell!// important step...
    if indexPath.section == 0 {
    cell = collectionView.dequeueReusableCellWithReuseIdentifier("collectionViewCell", forIndexPath: indexPath) as! CollectionCell

 //do something inside this

        }
    else if indexPath.section == 1 {
     cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! CollectionCell

       //here the static cell...   


    }
    return cell
    }
Run Code Online (Sandbox Code Playgroud)