Collection view only shows the first section, but doesn't show the second section.
Here are the delegates
private func numberOfSectionsInCollectionView(collectionView: UICollectionView!) -> Int {
return 2
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
var returnValue = Int()
if section == 0 {
returnValue = 1
} else if section == 1 {
returnValue = self.section1DataSource.count
}
return returnValue
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
var cell = UICollectionViewCell()
let cellA:GroupPhoto = collectionView.dequeueReusableCell(withReuseIdentifier: "groupPhotoCard", for: indexPath) as! GroupPhoto
let cellB:AddFriendCell = collectionView.dequeueReusableCell(withReuseIdentifier: "addFriendCard", for: indexPath) as! AddFriendCell
let section = indexPath.section
if section == 0 {
cell = cellA
//end of section 0
} else if section == 1 {
cell = cellB
}
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
var returnValue = CGSize()
if indexPath.section == 0 {
returnValue = CGSize(width: collectionView.frame.size.width, height: collectionView.frame.size.height / 3.0 - 8)
} else if indexPath.section == 1 {
returnValue = CGSize(width: collectionView.frame.size.width / 2.9 - 8, height: collectionView.frame.size.height / 2.9 - 8)
}
return returnValue
}
When I interchange the conditions so that the first section's cell will be assigned to the second section. It works fine, but it will still only show the first section and not the second.
Just like you would for a single cell. Dragging multiple cells into your collection view in a Storyboard automatically registers these cells on your collection view.
Select the starter app project's Views folder and click Create to create the file. Next, open Main. storyboard and select the collection view in FlickrPhotosViewController . Select the Attributes inspector and, in the Accessories section, check the Section Header checkbox.
Tableiw is a simple list, which displays single-dimensional rows of data. It's smooth because of cell reuse and other magic. 2. UICollectionView is the model for displaying multidimensional data .
Overview. A flow layout is a type of collection view layout. Items in the collection view flow from one row or column (depending on the scrolling direction) to the next, with each row containing as many cells as will fit. Cells can be the same sizes or different sizes.
Signature of numberOfSections(in:)
is changed in Swift 3 it should be like this.
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 2
}
In swift 3, numberOfSectionsInCollectionView is changed to numberOfSections(in:)
To avoid this, you should add UICollectionViewDataSource, to implement autocomplete.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With