Collection view and protocols - Collection View

7 important questions on Collection view and protocols - Collection View

What does a UICollectionView do?

It "lays out" little boxes with something in it, usually a custom view. There are as many "boxes" as the model provides.

What determines the layout of the UICollectionView?

Its layout object. iOS has only 1 "pre fabled" layout, called UICollectionViewFlowLayout

How does the FlowLayout lays out the boxes?

Like text, left to right and begins scrolling, when there's not enough space. 
  • Higher grades + faster learning
  • Never study anything twice
  • 100% sure, 100% understanding
Discover Study Smart

What is a UICollectionViewCell?

Its whats in the "little box" in a collection view. It is actually a view itself, with a property "contentView". This property holds the view which is in the Cell.

How can you set the controller as dataSource for the UICollectionView?

1: control-drag from the collection view to the controller in the storieboard.
2.you can do it in code:

We can do this using the controllers UICollectionViews outlet setter:

-(void)setCardCollectionView:(UICollectionView *)cardCollectionView
{
    _cardCollectionView = cardCollectionView;
    _cardCollectionView.dataSource = self;
    _cardCollectionView.delegate = self;
}

Which datasource protocol method do you implement to "tell" how many little boxes there are in a collection view?

-(NSInteger)collectionView: (UICollectionView *) asker numberOfItemsInSection:(NSInteger)section
{
  return numberOfBoxes;
}

What is a NSIndexPath object?

Its an object with an item property and a section property

The question on the page originate from the summary of the following study material:

  • A unique study and practice tool
  • Never study anything twice again
  • Get the grades you hope for
  • 100% sure, 100% understanding
Remember faster, study better. Scientifically proven.
Trustpilot Logo