Reputation: 73
I have a custom dynamic cell on a collectionView created on IB which will be filled with data from an array.
I want to add a static cell on the same CollectionView IB. Is it possible that the static cell to be on the last object of Collection View, no matter what array length is from dynamic cell the static cell would be added as last object?
Upvotes: 5
Views: 2075
Reputation:
here is the code for doing this.. I tried this method... For dynamic cell and static cell...
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
}
Upvotes: 1