Skip to Content
Programming iOS 14
book

Programming iOS 14

by Matt Neuburg
November 2020
Beginner
1256 pages
34h 47m
English
O'Reilly Media, Inc.
Content preview from Programming iOS 14

Chapter 9. Collection Views

A collection view (UICollectionView) is a UIScrollView that generalizes the notion of a table view (Chapter 8). Where a table view has rows, a collection view has items. (UICollectionView extends IndexPath so that you can refer to its item property instead of its row property, though in fact they are interchangeable.)

If you mentally substitute for items for rows, you’ll find that, knowing about table views, you know a great deal about collection views already:

  • The items are portrayed by reusable cells. These are UICollectionViewCell instances. If the collection view is instantiated from a storyboard, you can get reusable cells from the storyboard; otherwise, you’ll register a class or nib with the collection view.

  • A collection view can clump its items into sections.

  • A collection view has a data source (UICollectionViewDataSource) and a delegate (UICollectionViewDelegate), and it’s going to ask the data source Three Big Questions:

    • numberOfSections(in:)

    • collectionView(_:numberOfItemsInSection:)

    • collectionView(_:cellForItemAt:)

    Alternatively, starting in iOS 13, you can use a UICollectionViewDiffableDataSource.

  • To answer the third Big Question, your data source will obtain a reusable cell by dequeuing it from the collection view:

    • dequeueReusableCell(withReuseIdentifier:for:)

  • A collection view allows the user to select a cell, or multiple cells. The delegate is notified of highlighting and selection.

  • Your code can rearrange the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

iOS 15 Programming for Beginners - Sixth Edition

iOS 15 Programming for Beginners - Sixth Edition

Ahmad Sahar, Craig Clayton
Mastering iOS 14 Programming - Fourth Edition

Mastering iOS 14 Programming - Fourth Edition

Mario Eguiluz Alebicto, Chris Barker, Donny Wals

Publisher Resources

ISBN: 9781492092162Errata Page