Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CollectionView sizeForItemAtIndexPath never called

Tags:

ios

This is driving me crazy! I have a UICollectionViewController as shown below:

class PhrasesCompactCollectionViewController: UICollectionViewController 

The numberOfSections and cellForItemAt are being called but the sizeForItemAtIndexPath is never called. I am using the same exact code somewhere else and it fires correctly. I am using Xcode 8 Beta 6.

func collectionView(collectionView: UICollectionView,                         layout collectionViewLayout: UICollectionViewLayout,                         sizeForItemAtIndexPath indexPath:  NSIndexPath) -> CGSize {          return CGSize(width: 120, height:120)      } 
like image 399
john doe Avatar asked Aug 23 '16 17:08

john doe


People also ask

How do I change the appearance of each item in a collectionview?

The appearance of each item in the list can be defined by setting the ItemTemplate property to a DataTemplate. By default, a CollectionView will display its items in a vertical list. However, vertical and horizontal lists and grids can be specified. By default, CollectionView selection is disabled.

What is the default display of a collectionview?

By default, a CollectionView will display its items in a vertical list. However, vertical and horizontal lists and grids can be specified. By default, CollectionView selection is disabled. However, single and multiple selection can be enabled.

What is collectionview in Salesforce?

The CollectionView is a flexible and performant view for presenting lists of data using different layout specifications. A CollectionView is populated with data by setting its ItemsSource property to any collection that implements IEnumerable.

Is it possible to select multiple items in a collectionview?

However, vertical and horizontal lists and grids can be specified. By default, CollectionView selection is disabled. However, single and multiple selection can be enabled. In CollectionView, an empty view can be specified that provides feedback to the user when no data is available for display.


2 Answers

You need to specify that you implement the protocol UICollectionViewDelegateFlowLayout in your class declaration.

class PhrasesCompactCollectionViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout

like image 95
almas Avatar answered Oct 11 '22 22:10

almas


I had the same problem. The one thing that helped me was to make the 'Estimated Size' for the Cell Size under the collectionView size inspector 'None'.

enter image description here

like image 20
Zenman C Avatar answered Oct 11 '22 23:10

Zenman C