IGListCollectionContext
Objective-C
@protocol IGListCollectionContext <NSObject>
                Swift
protocol ListCollectionContext : NSObjectProtocol
                The collection context provides limited access to the collection-related information that section controllers need for operations like sizing, dequeuing cells, inserting, deleting, reloading, etc.
- 
                  
                  
The size of the collection view. You can use this for sizing cells.
Declaration
Objective-C
@property (nonatomic, readonly) CGSize containerSize;Swift
var containerSize: CGSize { get } - 
                  
                  
The content insets of the collection view. You can use this for sizing cells.
Declaration
Objective-C
@property (nonatomic, readonly) UIEdgeInsets containerInset;Swift
var containerInset: UIEdgeInsets { get } - 
                  
                  
The adjusted content insets of the collection view. Equivalent to containerInset under iOS 11.
Declaration
Objective-C
@property (nonatomic, readonly) UIEdgeInsets adjustedContainerInset;Swift
var adjustedContainerInset: UIEdgeInsets { get } - 
                  
                  
The size of the collection view with content insets applied.
Declaration
Objective-C
@property (nonatomic, readonly) CGSize insetContainerSize;Swift
var insetContainerSize: CGSize { get } - 
                  
                  
The content offset of the collection view.
Declaration
Objective-C
@property (nonatomic, readonly) CGPoint containerContentOffset;Swift
var containerContentOffset: CGPoint { get } - 
                  
                  
The trait collection of the collection view.
Declaration
Objective-C
@property (nonatomic, readonly, nullable) UITraitCollection *traitCollection;Swift
var traitCollection: UITraitCollection? { get } - 
                  
                  
The current scrolling traits of the underlying collection view.
Declaration
Objective-C
@property (nonatomic, readonly) IGListCollectionScrollingTraits scrollingTraits;Swift
var scrollingTraits: IGListCollectionScrollingTraits { get } - 
                  
                  
A bitmask of experiments to conduct on the section controller.
Declaration
Objective-C
@property (nonatomic) IGListExperiment experiments;Swift
var experiments: IGListExperiment { get set } - 
                  
                  
Returns size of the collection view relative to the section controller.
Declaration
Objective-C
- (CGSize)containerSizeForSectionController: (nonnull IGListSectionController *)sectionController;Swift
func containerSize(for sectionController: IGListSectionController) -> CGSizeParameters
sectionControllerThe section controller requesting this information.
Return Value
The size of the collection view minus the given section controller’s insets.
 - 
                  
                  
Returns the index of the specified cell in the collection relative to the section controller.
Declaration
Objective-C
- (NSInteger)indexForCell:(nonnull UICollectionViewCell *)cell sectionController:(nonnull IGListSectionController *)sectionController;Swift
func index(for cell: UICollectionViewCell, sectionController: IGListSectionController) -> IntParameters
cellAn existing cell in the collection.
sectionControllerThe section controller requesting this information.
Return Value
The index of the cell or
NSNotFoundif it does not exist in the collection. - 
                  
                  
Returns the cell in the collection at the specified index for the section controller.
Warning
This method may return
nilif the cell is offscreen.Declaration
Objective-C
- (nullable __kindof UICollectionViewCell *) cellForItemAtIndex:(NSInteger)index sectionController:(nonnull IGListSectionController *)sectionController;Swift
func cellForItem(at index: Int, sectionController: IGListSectionController) -> UICollectionViewCell?Parameters
indexThe index of the desired cell.
sectionControllerThe section controller requesting this information.
Return Value
The collection view cell, or
nilif not found. - 
                  
                  
Returns the supplementary view in the collection at the specified index for the section controller.
Warning
This method may return
nilif the cell is offscreen.Declaration
Objective-C
- (nullable __kindof UICollectionReusableView *) viewForSupplementaryElementOfKind:(nonnull NSString *)elementKind atIndex:(NSInteger)index sectionController: (nonnull IGListSectionController *)sectionController;Swift
func viewForSupplementaryElement(ofKind elementKind: String, at index: Int, sectionController: IGListSectionController) -> UICollectionReusableView?Parameters
elementKindThe element kind of the supplementary view.
indexThe index of the desired cell.
sectionControllerThe section controller requesting this information.
Return Value
The collection reusable view, or
nilif not found. - 
                  
                  
Returns the fully visible cells for the given section controller.
Declaration
Objective-C
- (nonnull NSArray<UICollectionViewCell *> *) fullyVisibleCellsForSectionController: (nonnull IGListSectionController *)sectionController;Swift
func fullyVisibleCells(for sectionController: IGListSectionController) -> [UICollectionViewCell]Parameters
sectionControllerThe section controller requesting this information.
Return Value
An array of fully visible cells, or an empty array if none are found.
 - 
                  
                  
Returns the visible cells for the given section controller.
Declaration
Objective-C
- (nonnull NSArray<UICollectionViewCell *> *)visibleCellsForSectionController: (nonnull IGListSectionController *)sectionController;Swift
func visibleCells(for sectionController: IGListSectionController) -> [UICollectionViewCell]Parameters
sectionControllerThe section controller requesting this information.
Return Value
An array of visible cells, or an empty array if none are found.
 - 
                  
                  
Returns the visible paths for the given section controller.
Declaration
Objective-C
- (nonnull NSArray<NSIndexPath *> *)visibleIndexPathsForSectionController: (nonnull IGListSectionController *)sectionController;Swift
func visibleIndexPaths(for sectionController: IGListSectionController) -> [IndexPath]Parameters
sectionControllerThe section controller requesting this information.
Return Value
An array of visible index paths, or an empty array if none are found.
 - 
                  
                  
Deselects a cell in the collection.
Declaration
Objective-C
- (void)deselectItemAtIndex:(NSInteger)index sectionController:(nonnull IGListSectionController *)sectionController animated:(BOOL)animated;Swift
func deselectItem(at index: Int, sectionController: IGListSectionController, animated: Bool)Parameters
indexThe index of the item to deselect.
sectionControllerThe section controller requesting this information.
animatedPass
YESto animate the change,NOotherwise. - 
                  
                  
Selects a cell in the collection.
Declaration
Objective-C
- (void)selectItemAtIndex:(NSInteger)index sectionController:(nonnull IGListSectionController *)sectionController animated:(BOOL)animated scrollPosition:(UICollectionViewScrollPosition)scrollPosition;Swift
func selectItem(at index: Int, sectionController: IGListSectionController, animated: Bool, scrollPosition: UICollectionView.ScrollPosition)Parameters
indexThe index of the item to select.
sectionControllerThe section controller requesting this information.
animatedPass
YESto animate the change,NOotherwise.scrollPositionAn option that specifies where the item should be positioned when scrolling finishes.
 - 
                  
                  
Dequeues a cell from the collection view reuse pool.
Note
This method uses a string representation of the cell class as the identifier.
Declaration
Objective-C
- (nonnull __kindof UICollectionViewCell *) dequeueReusableCellOfClass:(nonnull Class)cellClass withReuseIdentifier:(nullable NSString *)reuseIdentifier forSectionController: (nonnull IGListSectionController *)sectionController atIndex:(NSInteger)index;Swift
func dequeueReusableCell(of cellClass: AnyClass, withReuseIdentifier reuseIdentifier: String?, for sectionController: IGListSectionController, at index: Int) -> UICollectionViewCellParameters
cellClassThe class of the cell you want to dequeue.
reuseIdentifierA reuse identifier for the specified cell. This parameter may be
nil.sectionControllerThe section controller requesting this information.
indexThe index of the cell.
Return Value
A cell dequeued from the reuse pool or a newly created one.
 - 
                  
                  
Dequeues a cell from the collection view reuse pool.
Note
This method uses a string representation of the cell class as the identifier.
Declaration
Objective-C
- (nonnull __kindof UICollectionViewCell *) dequeueReusableCellOfClass:(nonnull Class)cellClass forSectionController: (nonnull IGListSectionController *)sectionController atIndex:(NSInteger)index;Swift
func dequeueReusableCell(of cellClass: AnyClass, for sectionController: IGListSectionController, at index: Int) -> UICollectionViewCellParameters
cellClassThe class of the cell you want to dequeue.
sectionControllerThe section controller requesting this information.
indexThe index of the cell.
Return Value
A cell dequeued from the reuse pool or a newly created one.
 - 
                  
                  
Dequeues a cell from the collection view reuse pool.
Note
This method uses the nib name as the reuse identifier.
Declaration
Objective-C
- (nonnull __kindof UICollectionViewCell *) dequeueReusableCellWithNibName:(nonnull NSString *)nibName bundle:(nullable NSBundle *)bundle forSectionController: (nonnull IGListSectionController *)sectionController atIndex:(NSInteger)index;Swift
func dequeueReusableCell(withNibName nibName: String, bundle: Bundle?, for sectionController: IGListSectionController, at index: Int) -> UICollectionViewCellParameters
nibNameThe name of the nib file.
bundleThe bundle in which to search for the nib file. If
nil, this method searches the main bundle.sectionControllerThe section controller requesting this information.
indexThe index of the cell.
Return Value
A cell dequeued from the reuse pool or a newly created one.
 - 
                  
                  
Dequeues a storyboard prototype cell from the collection view reuse pool.
Declaration
Objective-C
- (nonnull __kindof UICollectionViewCell *) dequeueReusableCellFromStoryboardWithIdentifier: (nonnull NSString *)identifier forSectionController: (nonnull IGListSectionController *) sectionController atIndex:(NSInteger)index;Swift
func dequeueReusableCellFromStoryboard(withIdentifier identifier: String, for sectionController: IGListSectionController, at index: Int) -> UICollectionViewCellParameters
identifierThe identifier of the cell prototype in storyboard.
sectionControllerThe section controller requesting this information.
indexThe index of the cell.
Return Value
A cell dequeued from the reuse pool or a newly created one.
 - 
                  
                  
Dequeues a supplementary view from the collection view reuse pool.
Note
This method uses a string representation of the view class and the kind as the identifier.
Declaration
Objective-C
- (nonnull __kindof UICollectionReusableView *) dequeueReusableSupplementaryViewOfKind:(nonnull NSString *)elementKind forSectionController: (nonnull IGListSectionController *)sectionController class:(nonnull Class)viewClass atIndex:(NSInteger)index;Swift
func dequeueReusableSupplementaryView(ofKind elementKind: String, for sectionController: IGListSectionController, class viewClass: AnyClass, at index: Int) -> UICollectionReusableViewParameters
elementKindThe kind of supplementary view.
sectionControllerThe section controller requesting this information.
viewClassThe class of the supplementary view.
indexThe index of the supplementary view.
Return Value
A supplementary view dequeued from the reuse pool or a newly created one.
 - 
                  
                  
Dequeues a supplementary view from the collection view reuse pool.
Declaration
Objective-C
- (nonnull __kindof UICollectionReusableView *) dequeueReusableSupplementaryViewFromStoryboardOfKind: (nonnull NSString *)elementKind withIdentifier: (nonnull NSString *)identifier forSectionController: (nonnull IGListSectionController *) sectionController atIndex:(NSInteger)index;Swift
func dequeueReusableSupplementaryView(fromStoryboardOfKind elementKind: String, withIdentifier identifier: String, for sectionController: IGListSectionController, at index: Int) -> UICollectionReusableViewParameters
elementKindThe kind of supplementary view.
identifierThe identifier of the supplementary view in storyboard.
sectionControllerThe section controller requesting this information.
indexThe index of the supplementary view.
Return Value
A supplementary view dequeued from the reuse pool or a newly created one.
 - 
                  
                  
Dequeues a supplementary view from the collection view reuse pool.
Note
This method uses the nib name as the reuse identifier.
Declaration
Objective-C
- (nonnull __kindof UICollectionReusableView *) dequeueReusableSupplementaryViewOfKind:(nonnull NSString *)elementKind forSectionController: (nonnull IGListSectionController *)sectionController nibName:(nonnull NSString *)nibName bundle:(nullable NSBundle *)bundle atIndex:(NSInteger)index;Swift
func dequeueReusableSupplementaryView(ofKind elementKind: String, for sectionController: IGListSectionController, nibName: String, bundle: Bundle?, at index: Int) -> UICollectionReusableViewParameters
elementKindThe kind of supplementary view.
sectionControllerThe section controller requesting this information.
nibNameThe name of the nib file.
bundleThe bundle in which to search for the nib file. If
nil, this method searches the main bundle.indexThe index of the supplementary view.
Return Value
A supplementary view dequeued from the reuse pool or a newly created one.
 - 
                  
                  
Invalidate the backing
UICollectionViewLayoutfor all items in the section controller.Note
This method can be wrapped in
UIViewanimation APIs to control the duration or perform without animations. This will end up calling-[UICollectionView performBatchUpdates:completion:]internally, so invalidated changes may not be reflected in the cells immediately.Declaration
Objective-C
- (void)invalidateLayoutForSectionController: (nonnull IGListSectionController *)sectionController completion: (nullable void (^)(BOOL))completion;Swift
func invalidateLayout(for sectionController: IGListSectionController) async -> BoolParameters
sectionControllerThe section controller that needs invalidating.
completionAn optional completion block to execute when the updates are finished.
 - 
                  
                  
Batches and performs many cell-level updates in a single transaction.
Note
You should make state changes that impact the number of items in your section controller within the updates block alongside changes on the context object.
For example, inside your section controllers, you may want to delete and insert into the data source that backs your section controller. For example:
[self.collectionContext performBatchItemUpdates:^ (id<IGListBatchContext> batchContext>){ // perform data source changes inside the update block [self.items addObject:newItem]; [self.items removeObjectAtIndex:0]; NSIndexSet *inserts = [NSIndexSet indexSetWithIndex:[self.items count] - 1]; [batchContext insertInSectionController:self atIndexes:inserts]; NSIndexSet *deletes = [NSIndexSet indexSetWithIndex:0]; [batchContext deleteInSectionController:self atIndexes:deletes]; } completion:nil];Warning
You must perform data modifications inside the update block. Updates will not be performed synchronously, so you should make sure that your data source changes only when necessary.Declaration
Objective-C
- (void)performBatchAnimated:(BOOL)animated updates:(nonnull void (^)(id<IGListBatchContext> _Nonnull)) updates completion:(nullable void (^)(BOOL))completion;Swift
func performBatch(animated: Bool, updates: @escaping (any ListBatchContext) -> Void) async -> BoolParameters
animatedA flag indicating if the transition should be animated.
updatesA block with a context parameter to make mutations.
completionAn optional completion block to execute when the updates are finished.
 - 
                  
                  
Scrolls to the specified section controller in the list.
Declaration
Objective-C
- (void)scrollToSectionController: (nonnull IGListSectionController *)sectionController atIndex:(NSInteger)index scrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated;Swift
func scroll(to sectionController: IGListSectionController, at index: Int, scrollPosition: UICollectionView.ScrollPosition, animated: Bool)Parameters
sectionControllerThe section controller.
indexThe index of the item in the section controller to which to scroll.
scrollPositionAn option that specifies where the item should be positioned when scrolling finishes.
animatedA flag indicating if the scrolling should be animated.
 
View on GitHub