IGListSectionController

Objective-C


@interface IGListSectionController : NSObject

Swift

class ListSectionController : NSObject

The base class for section controllers used in a list. This class is intended to be subclassed.

  • Returns the number of items in the section.

    Note

    The count returned is used to drive the number of cells displayed for this section controller. The default implementation returns 1. Calling super is not required.

    Declaration

    Objective-C

    - (NSInteger)numberOfItems;

    Swift

    func numberOfItems() -> Int

    Return Value

    A count of items in the list.

  • The specific size for the item at the specified index.

    Note

    The returned size is not guaranteed to be used. The implementation may query sections for their layout information at will, or use its own layout metrics. For example, consider a dynamic-text sized list versus a fixed height-and-width grid. The former will ask each section for a size, and the latter will likely not. The default implementation returns size zero. Calling super is not required.

    Declaration

    Objective-C

    - (CGSize)sizeForItemAtIndex:(NSInteger)index;

    Swift

    func sizeForItem(at index: Int) -> CGSize

    Parameters

    index

    The row index of the item.

    Return Value

    The size for the item at index.

  • Return a dequeued cell for a given index.

    Note

    This is your opportunity to do any cell setup and configuration. The infrastructure requests a cell when it will be used on screen. You should never allocate new cells in this method, instead use the provided adapter to call one of the dequeue methods on the IGListCollectionContext. The default implementation will assert. You must override this method without calling super.

    Warning

    Don’t call this method to obtain a reference to currently dequeued cells: a new cell will be dequeued and returned, rather than the existing cell that you may have intended to retrieve. Instead, you can call -cellForItemAtIndex:sectionController: on IGListCollectionContext to obtain active cell references.

    Declaration

    Objective-C

    - (nonnull __kindof UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index;

    Swift

    func cellForItem(at index: Int) -> UICollectionViewCell

    Parameters

    index

    The index of the requested row.

    Return Value

    A configured UICollectionViewCell subclass.

  • Updates the section controller to a new object.

    Note

    When this method is called, all available contexts and configurations have been set for the section controller. This method will only be called when the object instance has changed, including from nil or a previous object. Calling super is not required.

    Declaration

    Objective-C

    - (void)didUpdateToObject:(nonnull id)object;

    Swift

    func didUpdate(to object: Any)

    Parameters

    object

    The object mapped to this section controller.

  • Asks the section controller if the cell at the specified index path should be selected

    Note

    The default implementation returns YES. Calling super is not required.

    Declaration

    Objective-C

    - (BOOL)shouldSelectItemAtIndex:(NSInteger)index;

    Swift

    func shouldSelectItem(at index: Int) -> Bool

    Parameters

    index

    The index of cell to be selected.

  • Asks the section controller if the cell at the specified index path should be deselected

    Note

    The default implementation returns YES. Calling super is not required.

    Declaration

    Objective-C

    - (BOOL)shouldDeselectItemAtIndex:(NSInteger)index;

    Swift

    func shouldDeselectItem(at index: Int) -> Bool

    Parameters

    index

    The index of cell to be deselected.

  • Tells the section controller that the cell at the specified index path was selected.

    Note

    The default implementation does nothing. Calling super is not required.

    Declaration

    Objective-C

    - (void)didSelectItemAtIndex:(NSInteger)index;

    Swift

    func didSelectItem(at index: Int)

    Parameters

    index

    The index of the selected cell.

  • Tells the section controller that the cell at the specified index path was deselected.

    Note

    The default implementation does nothing. Calling super is not required.

    Declaration

    Objective-C

    - (void)didDeselectItemAtIndex:(NSInteger)index;

    Swift

    func didDeselectItem(at index: Int)

    Parameters

    index

    The index of the deselected cell.

  • Tells the section controller that the cell at the specified index path was highlighted.

    Note

    The default implementation does nothing. Calling super is not required.

    Declaration

    Objective-C

    - (void)didHighlightItemAtIndex:(NSInteger)index;

    Swift

    func didHighlightItem(at index: Int)

    Parameters

    index

    The index of the highlighted cell.

  • Tells the section controller that the cell at the specified index path was unhighlighted.

    Note

    The default implementation does nothing. Calling super is not required.

    Declaration

    Objective-C

    - (void)didUnhighlightItemAtIndex:(NSInteger)index;

    Swift

    func didUnhighlightItem(at index: Int)

    Parameters

    index

    The index of the unhighlighted cell.

  • Identifies whether an object can be moved through interactive reordering.

    Note

    Interactive reordering is supported both for items within a single section, as well as for reordering sections themselves when sections contain only one item. The default implementation returns false.

    Declaration

    Objective-C

    - (BOOL)canMoveItemAtIndex:(NSInteger)index;

    Swift

    func canMoveItem(at index: Int) -> Bool

    Parameters

    index

    The index of the object in the list.

    Return Value

    YES if the object is allowed to move, otherwise NO.

  • Notifies the section that a list object should move within a section as the result of interactive reordering.

    Note

    this method must be implemented if interactive reordering is enabled.

    Declaration

    Objective-C

    - (void)moveObjectFromIndex:(NSInteger)sourceIndex
                        toIndex:(NSInteger)destinationIndex;

    Swift

    func moveObject(from sourceIndex: Int, to destinationIndex: Int)

    Parameters

    sourceIndex

    The starting index of the object.

    destinationIndex

    The ending index of the object.

  • The view controller housing the adapter that created this section controller.

    Note

    Use this view controller to push, pop, present, or do other custom transitions.

    Warning

    It is considered very bad practice to cast this to a known view controller and call methods on it other than for navigations and transitions.

    Declaration

    Objective-C

    @property (nonatomic, weak, readonly, nullable) UIViewController *viewController;

    Swift

    weak var viewController: UIViewController? { get }
  • A context object for interacting with the collection.

    Use this property for accessing the collection size, dequeuing cells, reloading, inserting, deleting, etc.

    Note

    When created outside of -listAdapter:sectionControllerForObject:, this object is temporarily nil after initialization. We bridge it to Swift as an implicitly-unwrapped Optional, so that idiomatic IGListKit code is not forced to handle nullability with explicit as! or fatalError, as using a non-nil instance of this object is essential for dequeueing cells.

    Declaration

    Objective-C

    @property (nonatomic, weak, readonly, null_unspecified) id<IGListCollectionContext> collectionContext;

    Swift

    weak var collectionContext: (any ListCollectionContext)! { get }
  • Returns the section within the list for this section controller.

    Note

    This value also relates to the section within a UICollectionView that this section controller’s cells belong. It also relates to the -[NSIndexPath section] value for individual cells within the collection view.

    Declaration

    Objective-C

    @property (nonatomic, readonly) NSInteger section;

    Swift

    var section: Int { get }
  • Returns YES if the section controller is the first section in the list, NO otherwise.

    Declaration

    Objective-C

    @property (nonatomic, readonly) BOOL isFirstSection;

    Swift

    var isFirstSection: Bool { get }
  • Returns YES if the section controller is the last section in the list, NO otherwise.

    Declaration

    Objective-C

    @property (nonatomic, readonly) BOOL isLastSection;

    Swift

    var isLastSection: Bool { get }
  • The margins used to lay out content in the section controller.

    See

    -[UICollectionViewFlowLayout sectionInset].

    Declaration

    Objective-C

    @property (nonatomic) UIEdgeInsets inset;

    Swift

    var inset: UIEdgeInsets { get set }
  • The minimum spacing to use between rows of items.

    See

    -[UICollectionViewFlowLayout minimumLineSpacing].

    Declaration

    Objective-C

    @property (nonatomic) CGFloat minimumLineSpacing;

    Swift

    var minimumLineSpacing: CGFloat { get set }
  • The minimum spacing to use between items in the same row.

    See

    -[UICollectionViewFlowLayout minimumInteritemSpacing].

    Declaration

    Objective-C

    @property (nonatomic) CGFloat minimumInteritemSpacing;

    Swift

    var minimumInteritemSpacing: CGFloat { get set }
  • The supplementary view source for the section controller. Can be nil.

    Note

    You may wish to return self if your section controller implements this protocol.

    Declaration

    Objective-C

    @property (nonatomic, weak, nullable) id<IGListSupplementaryViewSource> supplementaryViewSource;

    Swift

    weak var supplementaryViewSource: (any ListSupplementaryViewSource)? { get set }

    Return Value

    An object that conforms to IGListSupplementaryViewSource or nil.

  • An object that handles display events for the section controller. Can be nil.

    Note

    You may wish to return self if your section controller implements this protocol.

    Declaration

    Objective-C

    @property (nonatomic, weak, nullable) id<IGListDisplayDelegate> displayDelegate;

    Swift

    weak var displayDelegate: (any ListDisplayDelegate)? { get set }

    Return Value

    An object that conforms to IGListDisplayDelegate or nil.

  • An object that handles working range events for the section controller. Can be nil.

    Note

    You may wish to return self if your section controller implements this protocol.

    Declaration

    Objective-C

    @property (nonatomic, weak, nullable) id<IGListWorkingRangeDelegate> workingRangeDelegate;

    Swift

    weak var workingRangeDelegate: (any ListWorkingRangeDelegate)? { get set }

    Return Value

    An object that conforms to IGListWorkingRangeDelegate or nil.

  • An object that handles scroll events for the section controller. Can be nil.

    Note

    You may wish to return self if your section controller implements this protocol.

    Declaration

    Objective-C

    @property (nonatomic, weak, nullable) id<IGListScrollDelegate> scrollDelegate;

    Swift

    weak var scrollDelegate: (any ListScrollDelegate)? { get set }

    Return Value

    An object that conforms to IGListScrollDelegate or nil.

  • An object that handles transition events for the section controller. Can be nil.

    Note

    You may wish to return self if your section controller implements this protocol.

    Declaration

    Objective-C

    @property (nonatomic, weak, nullable) id<IGListTransitionDelegate> transitionDelegate;

    Swift

    weak var transitionDelegate: (any IGListTransitionDelegate)? { get set }

    Return Value

    An object that conforms to IGListTransitionDelegat or nil.