IGListCollectionContext

@protocol IGListCollectionContext <NSObject>

The collection context provides limited access to the collection related information that section controllers need for things like sizing, dequeing cells, insterting/deleting/reloading, etc.

  • Size of the collection view. Provided primarily for sizing cells.

    Declaration

    Objective-C

    @property (readonly, nonatomic) CGSize containerSize;

    Swift

    var containerSize: Int32 { get }
  • Query for the index a cell in the collection relative to the section controller.

    Declaration

    Objective-C

    - (NSUInteger)indexForCell:(nonnull UICollectionViewCell *)cell
             sectionController:
                 (nonnull IGListSectionController<IGListSectionType> *)
                     sectionController;

    Swift

    func index(forCell cell: Any!, sectionController: Any!) -> Any!

    Parameters

    cell

    An existing cell in the collection.

    sectionController

    The section controller requesting this information.

    Return Value

    The index of the cell or NSNotFound if it does not exist in the collection.

  • Query for a cell in the collection. May return nil if the cell is offscreen.

    Declaration

    Objective-C

    - (nullable __kindof UICollectionViewCell *)
    cellForItemAtIndex:(NSInteger)index
     sectionController:
         (nonnull IGListSectionController<IGListSectionType> *)sectionController;

    Swift

    func cellForItem(atIndex index: Any!, sectionController: Any!) -> Any!

    Parameters

    index

    The index of the desired cell.

    sectionController

    The section controller requesting this information.

    Return Value

    The collection view cell, or nil if not found.

  • Query for the visible cells for the given section controller.

    Declaration

    Objective-C

    - (nonnull NSArray<UICollectionViewCell *> *)visibleCellsForSectionController:
        (nonnull IGListSectionController<IGListSectionType> *)sectionController;

    Swift

    func visibleCells(forSectionController sectionController: Any!) -> Any!

    Parameters

    sectionController

    The section controller requesting this information.

    Return Value

    An array of visible cells, or an empty array if none are found.

  • Deselects a cell in the collection.

    Declaration

    Objective-C

    - (void)deselectItemAtIndex:(NSInteger)index
              sectionController:
                  (nonnull IGListSectionController<IGListSectionType> *)
                      sectionController
                       animated:(BOOL)animated;

    Swift

    func deselectItem(atIndex index: Any!, sectionController: Any!, animated: Any!)

    Parameters

    index

    The index of the item to deselect.

    sectionController

    The section controller requesting this information.

    animated

    Pass YES to animate the change, NO otherwise.

  • Query the section index of an section controller.

    Declaration

    Objective-C

    - (NSUInteger)sectionForSectionController:
        (nonnull IGListSectionController<IGListSectionType> *)sectionController;

    Swift

    func section(forSectionController sectionController: Any!) -> Any!

    Parameters

    sectionController

    An section controller object.

    Return Value

    The section index of the list if found, otherwise NSNotFound.

  • Dequeues a cell from the UICollectionView 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<IGListSectionType> *)
                  sectionController
                       atIndex:(NSInteger)index;

    Swift

    func dequeueReusableCell(of cellClass: AnyClass!, forSectionController sectionController: Any!, atIndex index: Any!) -> Any!

    Parameters

    cellClass

    The class of the cell you want to dequeue.

    sectionController

    The section controller requesting this information.

    index

    The index of the cell.

    Return Value

    A cell dequeued from the reuse pool or newly created.

  • Dequeues a supplementary view from the UICollectionView reuse pool.

    Note

    This method uses a string representation of the view class as the identifier.

    Declaration

    Objective-C

    - (nonnull __kindof UICollectionReusableView *)
    dequeueReusableSupplementaryViewOfKind:(nonnull NSString *)elementKind
                      forSectionController:
                          (nonnull IGListSectionController<IGListSectionType> *)
                              sectionController
                                     class:(nonnull Class)viewClass
                                   atIndex:(NSInteger)index;

    Swift

    func dequeueReusableSupplementaryView(ofKind elementKind: Any!, forSectionController sectionController: Any!, class viewClass: AnyClass!, atIndex index: Any!) -> Any!

    Parameters

    elementKind

    The kind of supplementary veiw.

    sectionController

    The section controller requesting this information.

    viewClass

    The class of the supplementary view.

    index

    The index of the supplementary vew.

    Return Value

    A supplementary view dequeued from the reuse pool or newly created.

  • Reloads cells in the section controller.

    Declaration

    Objective-C

    - (void)reloadInSectionController:
                (nonnull IGListSectionController<IGListSectionType> *)
                    sectionController
                            atIndexes:(nonnull NSIndexSet *)indexes;

    Swift

    func reload(inSectionController sectionController: Any!, atIndexes indexes: Any!)

    Parameters

    sectionController

    The section controller who’s cells need reloading.

    indexes

    The indexes of items that need reloading.

  • Inserts cells in the feed.

    Declaration

    Objective-C

    - (void)insertInSectionController:
                (nonnull IGListSectionController<IGListSectionType> *)
                    sectionController
                            atIndexes:(nonnull NSIndexSet *)indexes;

    Swift

    func insert(inSectionController sectionController: Any!, atIndexes indexes: Any!)

    Parameters

    sectionController

    The section controller who’s cells need inserting.

    indexes

    The indexes of items that need inserting.

  • Deletes cells in the feed.

    Declaration

    Objective-C

    - (void)deleteInSectionController:
                (nonnull IGListSectionController<IGListSectionType> *)
                    sectionController
                            atIndexes:(nonnull NSIndexSet *)indexes;

    Swift

    func delete(inSectionController sectionController: Any!, atIndexes indexes: Any!)

    Parameters

    sectionController

    The section controller who’s cells need deleted.

    indexes

    The indexes of items that need deleting.

  • Reload the entire section controller.

    Declaration

    Objective-C

    - (void)reloadSectionController:
        (nonnull IGListSectionController<IGListSectionType> *)sectionController;

    Swift

    func reloadSectionController(_ sectionController: Any!)

    Parameters

    sectionController

    The list object who’s cells need reloading.

  • Batch many cell-level updates in a single transaction.

    @discussion Use this method to batch cell updates (inserts, deletes, reloads) into a single transaction. This lets you make many changes to your data store and perform all the transitions at once.

    For example, inside your section controllers, you may want to delete /and/ insert into the data source that backs your section controller:

    [self.collectionContext performBatchItemUpdates:^{ // perform data source changes inside the update block [self.items addObject:newItem]; [self.items removeObjectAtIndex:0];

    NSIndexSet *inserts = [NSIndexSet indexSetWithIndex:[self.items count] - 1]; [self.collectionContext insertInSectionController:self atIndexes:inserts];

    NSIndexSet *deletes = [NSIndexSet indexSetWithIndex:0]; [self.collectionContext deleteInSectionController:self deletes]; } completion:nil];

    Note that 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 (^)())updates
                      completion:(nullable void (^)(BOOL))completion;

    Swift

    func performBatchAnimated(_ animated: Any!, updates: (@escaping () -> Void)!, completion: (@escaping (Int32) -> Void)? = nil)

    Parameters

    animated

    A flag indicating if the transition should be animated.

    updates

    A block containing all of the cell updates.

    completion

    An optional completion block to execute when the updates are finished.