Professional Documents
Culture Documents
Session 232
Jeff Watkins
iOS Software Engineer
© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.
Introduction
Implemented in UICollectionViewController
Either
• One gigantic controller
• One controller per content type
Doesn’t encourage code reuse for similar sections
Aggregate Data Source
AAPLDataSource
The base data source class
AAPLSegmentedDataSource
Multiple children; only one active at a time
AAPLComposedDataSource
Multiple children; all active at once
AAPLBasicDataSource
One section; items stored in an NSArray
Segmented Data Source
Details
Episodes
Reviews
Trends
Composed Data Source
Details
Episodes
Reviews
Trends
Composed Data Source
Details
• Status
Episodes
Reviews
Trends
Composed Data Source
Details
• Status
• Information
Episodes
Reviews
Trends
Composed Data Source
Details
• Status
• Information
• Description
Episodes
Reviews
Trends
Basic Data Source
Details
Episodes
Reviews
Trends
Composed Data Source
Details
Episodes
Reviews
Trends
Composed Data Source
Details
Episodes
Reviews
• Ratings
Trends
Composed Data Source
Details
Episodes
Reviews
• Ratings
• Reviews
Trends
Custom Data Source
Details
Episodes
Reviews
Trends
Custom Data Source
Details
Episodes
Reviews
Trends
• Graph
Custom Data Source
Details
Episodes
Reviews
Trends
• Graph
• History
Single Loading Indicator
Single Loading Indicator
No
Content
Refresh-
Loading Content ing
Initial
Content Loaded
Content
Error
Cat List
No
Content Data Source
Refresh-
Loading Content ing
Initial
Content Loaded
Content
Error
Cat List
No
Content Data Source
Refresh-
Loading Content ing
Initial
Content Loaded
Content
GET http://example.com/cats/
Error
Cat List
No
Content Data Source
Refresh-
Loading Content ing
Initial
Content Loaded
Content
200 OK
Error
No
Content
Refresh-
Loading Content ing
Initial
Content Loaded
Content
Error
No
Content
Refresh-
Loading Content ing
Initial
Content Loaded
Content
Error
No
Content
Refresh-
Loading Content ing
Initial
Content Loaded
Content
Error
No
Content
Refresh-
Loading Content ing
Initial
Content Loaded
Content
Error
No
Content
Refresh-
Loading Content ing
Initial
Content Loaded
Content
Error
No
Content
Refresh-
Loading Content ing
Initial
Content Loaded
Content
Error
Aggregate Data Sources
Ratings Data
Source
Initial
Composed
Data Source
Initial
Reviews Data
Source
Initial
Aggregate Data Sources
Ratings Data
Source
Loading Content
Composed
Data Source
Loading Content
Reviews Data
Source
Loading Content
Aggregate Data Sources
GET http://example.com/ratings/
Ratings Data
Source
Loading Content
Composed
Data Source
Loading Content
Reviews Data
Source
Loading Content GET http://example.com/reviews/
Aggregate Data Sources
GET http://example.com/ratings/
Ratings Data
Source
Content Loaded
Composed
Data Source
200 OK
Loading Content
Reviews Data
Source
Loading Content GET http://example.com/reviews/
Aggregate Data Sources
GET http://example.com/ratings/
Ratings Data
Source
^{…}
Content Loaded
Composed
Data Source
200 OK
Loading Content
Reviews Data
Source
Loading Content GET http://example.com/reviews/
Aggregate Data Sources
GET http://example.com/ratings/
Ratings Data
Source
^{…}
Content Loaded 200 OK
Composed
Data Source
200 OK
Loading Content
Reviews Data
Source
Content Loaded GET http://example.com/reviews/
Aggregate Data Sources
GET http://example.com/ratings/
Ratings Data
Source
^{…}
^{…}
Content Loaded 200 OK
Composed
Data Source
200 OK
Loading Content
Reviews Data
Source
Content Loaded GET http://example.com/reviews/
Aggregate Data Sources
Ratings Data
Source [collectionView performBatchUpdates:^{
^{…}
^{…}
!
Content Loaded
Composed !
Data Source !
Content Loaded !
Ratings Data
Source [collectionView performBatchUpdates:^{
!
Content Loaded ^{…}
Composed !
Data Source !
^{…}
Content Loaded !
Ocelot
The Ocelot is also known as the dwarf leopard.
Tiger
The tiger is the largest of the cat species.
Mountain Lion
Like almost all cats, the mountain lion is a solitary animal.
Section Metrics
Ocelot
rowHeight The Ocelot is also known as the dwarf leopard.
Tiger
The tiger is the largest of the cat species.
Mountain Lion
Like almost all cats, the mountain lion is a solitary animal.
Section Metrics
Ocelot
rowHeight The Ocelot is also known as the dwarf leopard.
backgroundColor
Tiger
The tiger is the largest of the cat species.
Mountain Lion
Like almost all cats, the mountain lion is a solitary animal.
Section Metrics
Ocelot
rowHeight The Ocelot is also known as the dwarf leopard.
backgroundColor
Tiger
separatorColor and
The tiger is the largest of the cat species.
Ocelot
rowHeight The Ocelot is also known as the dwarf leopard.
backgroundColor
Tiger
separatorColor and The tiger is the largest of the cat species.
selectedBackgroundColor
Section Metrics
numberOfColumns
Ocelot Leopard
The Ocelot is also known as the dwarf leopard. The leopard is the smallest of the four big cats.
Tiger Lion
The tiger is the largest of the cat species. The male lion is easily recognized by its mane.
Ocelot Leopard
The Ocelot is also known as the dwarf leopard. The leopard is the smallest of the four big cats.
Tiger Lion
The tiger is the largest of the cat species. The male lion is easily recognized by its mane.
showsColumnSeparator
Header and Footer Metrics
Ocelot
The Ocelot is also known as the dwarf leopard.
Tiger
The tiger is the largest of the cat species.
Mountain Lion
Like almost all cats, the mountain lion is a solitary animal.
Header and Footer Metrics
Ocelot
The Ocelot is also known as the dwarf leopard.
Tiger
The tiger is the largest of the cat species.
Mountain Lion
Like almost all cats, the mountain lion is a solitary animal.
Header and Footer Metrics
Tiger
The tiger is the largest of the cat species.
Mountain Lion
Like almost all cats, the mountain lion is a solitary animal.
Header and Footer Metrics
Mountain Lion
Like almost all cats, the mountain lion is a solitary animal.
Custom Attributes
backgroundColor
selectedBackgroundColor
padding
pinnedHeader
Global Headers
Status
Data Source
Description
Data Source
Snapshot Metrics Section 0
Status
Data Source
Description
Data Source
Snapshot Metrics Section 0
Status
Data Source
rowHeight = 44
backgroundColor = light-
Grey
Description
Data Source
Snapshot Metrics Section 0
rowHeight = 44
backgroundColor = lightGrey
Status
Data Source
Description
Data Source
Snapshot Metrics Section 0
rowHeight = 44
backgroundColor = lightGrey
Status
Data Source
Description
Data Source
Snapshot Metrics Section 0
rowHeight = 44
backgroundColor = lightGrey
rowHeight = 60
selectedBackgroundColor =
Status
Data Source
mediumGrey
Description
Data Source
Snapshot Metrics Section 0
rowHeight = 60
backgroundColor = lightGrey
Status selectedBackgroundColor =
Data Source mediumGrey
Description
Data Source
Optional Layout Methods
Old New
-prepareForCollectionViewUpdates:
Deletions
Insertions
Old New
-prepareForCollectionViewUpdates:
Deletions
Insertions
Old New
-prepareForCollectionViewUpdates:
Deletions
Insertions
Old New
-prepareForCollectionViewUpdates:
Deletions
Insertions
Old New
Target Content Offset
-targetContentOffsetForProposedContentOffset:
contentSize: 320x645
contentOffset: 0, 432
Before
Bacon ipsum dolor sit amet
tri-tip beef ribs brisket sirloin
turkey venison prosciutto
shoulder swine. Jerky
pastrami turkey kielbasa,
venison pig meatloaf fatback
capicola. Cow pancetta swine,
ham hock ground round
bresaola meatloaf pig spare
ribs short ribs short loin beef
ribs kielbasa. Frankfurter
meatloaf short ribs shank
contentSize:
hamburger salami320x645
bacon tail
ham pork belly. Short0,loin
contentOffset: 165
swine cow ham, venison
porchetta beef ribs corned
beef flank. Filet mignon
ground round andouille tri-
tip. Kevin andouille pastrami
jerky ground round, sirloin
ham hock.
lorem feugiat porttitor.
Donec vitae posuere erat. Ut
After eu nisl ultrices, laoreet ligula
ac, bibendum diam. Cras
purus massa, vulputate a
accumsan quis, tempor sed
sem. In quis turpis enim. In
gravida, purus at scelerisque
eleifend, ante augue blandit
dui, id pulvinar justo nibh
non dolor. Duis scelerisque
urna et enim hendrerit
ullamcorper. Nam porta
rutrum urna, viverra tincidunt
velit ultricies mattis. Sed in
dui sed lorem varius
sollicitudin. Pellentesque sed
contentSize:
malesuada nibh, 320x1000
vel pretium
tellus. Sed arcu dolor,
contentOffset: 0, 432 gravida
eget lacus at, posuere
malesuada dolor. Proin at dui
gravida dui facilisis
consectetur sit amet eu
mauris. Donec sed felis
facilisis, congue nisl at,
gravida diam.
bresaola meatloaf pig spare
ribs short ribs short loin beef
After ribs kielbasa. Frankfurter
meatloaf short ribs shank
hamburger salami bacon tail
ham pork belly. Short loin
swine cow ham, venison
porchetta beef ribs corned
beef flank. Filet mignon
ground round andouille tri-
tip. Kevin andouille pastrami
jerky ground round, sirloin
ham hock.
contentSize: 320x645
contentOffset: 0, 0
After
size: 320x645
origin: 0, 0
Without Initial Layout Attributes
Bacon ipsum dolor sit amet
tri-tip beef ribs brisket sirloin
turkey venison prosciutto
shoulder swine. Jerky
pastrami turkey kielbasa,
venison pig meatloaf fatback
capicola. Cow pancetta swine,
ham hock ground round
bresaola meatloaf pig spare
size:
ribs short ribs320x645
short loin beef
ribs kielbasa. Frankfurter
origin: 0, 0
meatloaf short ribs shank
hamburger salami bacon tail
ham pork belly. Short loin
swine cow ham, venison
porchetta beef ribs corned
beef flank. Filet mignon
ground round andouille tri-
tip. Kevin andouille pastrami
jerky ground round, sirloin
ham hock.
With Initial Layout Attributes
Bacon ipsum dolor sit amet
tri-tip beef ribs brisket sirloin
turkey venison prosciutto
shoulder swine. Jerky
pastrami turkey kielbasa,
venison pig meatloaf fatback
capicola. Cow pancetta swine,
ham hock ground round
bresaola meatloaf pig spare
size:
ribs short ribs320x645
short loin beef
ribs kielbasa.
origin:Frankfurter
0, 432
meatloaf short ribs shank
hamburger salami bacon tail
ham pork belly. Short loin
swine cow ham, venison
porchetta beef ribs corned
beef flank. Filet mignon
ground round andouille tri-
tip. Kevin andouille pastrami
jerky ground round, sirloin
ham hock.
With Initial Layout Attributes
Bacon ipsum dolor sit amet
tri-tip beef ribs brisket sirloin
turkey venison prosciutto
shoulder swine. Jerky
pastrami turkey kielbasa,
venison pig meatloaf fatback
capicola. Cow pancetta swine,
ham hock ground round
bresaola meatloaf pig spare
size:
ribs short ribs320x645
short loin beef
ribs kielbasa. Frankfurter
origin: 0, 0
meatloaf short ribs shank
hamburger salami bacon tail
ham pork belly. Short loin
swine cow ham, venison
porchetta beef ribs corned
beef flank. Filet mignon
ground round andouille tri-
tip. Kevin andouille pastrami
jerky ground round, sirloin
ham hock.
-initialLayoutAttributesForAppearingItemAtIndexPath:
AAPLCollectionViewGridLayoutAttributes *result =
[self.indexPathToItemAttributes[indexPath] copy];
!
…
-initialLayoutAttributesForAppearingItemAtIndexPath:
AAPLCollectionViewGridLayoutAttributes *result =
[self.indexPathToItemAttributes[indexPath] copy];
!
…
-initialLayoutAttributesForAppearingItemAtIndexPath:
AAPLCollectionViewGridLayoutAttributes *result =
[self.indexPathToItemAttributes[indexPath] copy];
!
…
-initialLayoutAttributesForAppearingItemAtIndexPath:
AAPLCollectionViewGridLayoutAttributes *result =
[self.indexPathToItemAttributes[indexPath] copy];
!
…
-initialLayoutAttributesForAppearingItemAtIndexPath:
…
!
if (inserted)
result.alpha = 0;
!
results.frame = CGRectOffset(results.frame,
-self.contentOffsetDelta.x, -self.contentOffsetDelta.y);
return results;
-initialLayoutAttributesForAppearingItemAtIndexPath:
…
!
if (inserted)
result.alpha = 0;
!
results.frame = CGRectOffset(results.frame,
-self.contentOffsetDelta.x, -self.contentOffsetDelta.y);
return results;
-initialLayoutAttributesForAppearingItemAtIndexPath:
…
!
if (inserted)
result.alpha = 0;
!
results.frame = CGRectOffset(results.frame,
-self.contentOffsetDelta.x, -self.contentOffsetDelta.y);
return results;
UICollectionViewLayout
Recap
cell.editActions = @[
[AAPLAction actionWithTitle:favoriteTitle
selector:@selector(makeFavorite:)],
[AAPLAction destructiveActionWithTitle:deleteTitle
selector:@selector(swipeToDeleteCell:)]
];
Additional Custom Attributes
columnIndex
editing
movable
Swipe to Edit
One column
Ocelot
The Ocelot is also known as the dwarf leopard.
Tiger ★ Delete
The tiger is the largest of the cat species.
Mountain Lion
Like almost all cats, the mountain lion is a solitary animal.
Swipe to Edit
One column
Ocelot
The Ocelot is also known as the dwarf leopard.
Tiger ★ Delete
The tiger is the largest of the cat species.
Mountain Lion
Like almost all cats, the mountain lion is a solitary animal.
Swipe to Edit
Two column
Ocelot Leopard
The Ocelot is also known as the dwarf leopard. The leopard is the smallest of the four big cats.
Ocelot Leopard
The Ocelot is also known as the dwarf leopard. The leopard is the smallest of the four big cats.
Tiger Lion
★ Delete ★ Delete
The tiger is the largest of the cat species.
The male lion is easily recognized by its mane.
Ocelot
The Ocelot is also known as the dwarf leopard.
Tiger
editing = NO ★
The tiger is the largest of the cat species.
Delete
Lion
The male lion is easily recognized by its mane.
Batch Editing
Ocelot
The Ocelot is also known as the dwarf leopard.
Tiger
editing = YES ★
The tiger is the largest of the cat species.
Delete movable = YES
Lion
The male lion is easily recognized by its mane.
Batch Editing
Ocelot
The Ocelot is also known as the dwarf leopard.
Tiger ★ Delete
The tiger is the largest of the cat species.
Lion
The male lion is easily recognized by its mane.
Batch Editing
Ocelot
The Ocelot is also known as the dwarf leopard.
Tiger ★ Delete
The tiger is the largest of the cat species.
Lion
The male lion is easily recognized by its mane.
AAPLSwipeToEditStateMachine
Tracking
Manages gesture recognizers
• UIPanGestureRecognizer
Editing
• UILongPressGestureRecognizer
States are somewhat complex
Works with our layout and cells Nothing
Animating
Shut
Animating
Open
Drag to Reorder
Jake Behrens
App Frameworks Evangelist
behrens@apple.com
Documentation
Collection View Programming Guide for iOS
http://developer.apple.com/ios
Apple Developer Forums
http://devforums.apple.com
Related Sessions
• Table View and Collection View Lab Frameworks Lab A Thursday 11:30AM