Inherits from UIView
Declared in SSCollectionView.h

Overview

Simple collection view.

My goals are to be similar to UITableView and NSCollectionView when possible. Only scrolling vertically is currently supported.

Editing will be my next focus. Then animating changes when data changes and an option to disable that.

Note: NSIndexPath is uses the same way UITableView uses it. The row property is used to specify the item instead of row. This is done to make working with other classes that use NSIndexPath (like NSFetchedResultsController) easier.

Tasks

Configuring a Collection View

Accessing Items and Sections

Scrolling the Collection View

Managing Selections

Inserting, Deleting, and Moving Items and Sections

Reloading the Collection View

Accessing Drawing Areas of the Collection View

Managing the Delegate and the Data Source

  •   dataSource

    The object that acts as the data source of the receiving collection view.

    property
  •   delegate

    The object that acts as the delegate of the receiving collection view.

    property

Properties

allowsSelection

A Boolean value that determines whether selecting items is enabled.

@property (nonatomic, assign) BOOL allowsSelection

Discussion

If the value of this property is YES, selecting is enabled, and if it is NO, selecting is disabled. The default is YES.

Declared In

SSCollectionView.h

backgroundView

The background view of the collection view.

@property (nonatomic, retain) UIView *backgroundView

Declared In

SSCollectionView.h

collectionFooterView

Returns an accessory view that is displayed below the collection.

@property (nonatomic, retain) UIView *collectionFooterView

Discussion

The default value is nil. The collection footer view is different from a section footer.

Declared In

SSCollectionView.h

collectionHeaderView

Returns an accessory view that is displayed above the collection.

@property (nonatomic, retain) UIView *collectionHeaderView

Discussion

The default value is nil. The collection header view is different from a section header.

Declared In

SSCollectionView.h

dataSource

The object that acts as the data source of the receiving collection view.

@property (nonatomic, assign) id<SSCollectionViewDataSource> dataSource

Declared In

SSCollectionView.h

delegate

The object that acts as the delegate of the receiving collection view.

@property (nonatomic, assign) id<SSCollectionViewDelegate> delegate

Declared In

SSCollectionView.h

extremitiesStyle

The style of the receiving collection view’s headers and footers.

@property (nonatomic, assign) SSCollectionViewExtremitiesStyle extremitiesStyle

Discussion

Setting to SSCollectionViewExtremitiesStyleFixed will cause the headers and footer to behave like a UITableView with its style set to UITableViewStylePlain. Setting to SSCollectionViewExtremitiesStyleScrolling will cause the headers and footer to behave like a UITableView with its style set to UITableViewStyleGrouped. The default is SSCollectionViewExtremitiesStyleFixed.

Declared In

SSCollectionView.h

minimumColumnSpacing

The minimum column spacing.

@property (nonatomic, assign) CGFloat minimumColumnSpacing

Discussion

The default is 0.0.

Declared In

SSCollectionView.h

numberOfSections

The number of sections in the collection view.

@property (nonatomic, assign, readonly) NSUInteger numberOfSections

Discussion

SSCollectionView gets the value returned by this method from its data source and caches it.

Declared In

SSCollectionView.h

rowBackgroundColor

The background color of a row.

@property (nonatomic, retain) UIColor *rowBackgroundColor

Discussion

This will be the background of the collection view if nil is provided. The default is nil.

Declared In

SSCollectionView.h

rowSpacing

The spacing between each row in the receiver. This does not add space above the first row or below the last.

@property (nonatomic, assign) CGFloat rowSpacing

Discussion

The row spacing is in points. The default is 20.0.

Declared In

SSCollectionView.h

scrollView

The internal scroll view of the collection view. This should only be used to inspect its state or scrolling. Changing the value of its attributes is undefined.

@property (nonatomic, retain, readonly) UIScrollView *scrollView

Declared In

SSCollectionView.h

Instance Methods

beginUpdates

Begin a series of method calls that insert, delete, or select items and sections of the receiver.

- (void)beginUpdates

Discussion

Call this method if you want subsequent insertions, deletion, and selection operations (for example, itemForIndexPath: and indexPathsForVisibleItems) to be animated simultaneously. This group of methods must conclude with an invocation of endUpdates. These method pairs can be nested. If you do not make the insertion, deletion, and selection calls inside this block, collection view attributes such as item count might become invalid. You should not call reloadData within the group; if you call this method within the group, you will need to perform any animations yourself.

This functionality was introduced in version 0.1.1 and still considered in development. During development, it has proven to be stable, but use with care.

See Also

Declared In

SSCollectionView.h

deleteItemsAtIndexPaths:withItemAnimation:

Deletes the items specified by an array of index paths, with an option to animate the deletion.

- (void)deleteItemsAtIndexPaths:(NSArray *)indexPaths withItemAnimation:(SSCollectionViewItemAnimation)animation

Parameters

indexPaths

An array of NSIndexPath objects each representing a item index and section index that together identify an item in the collection view.

animation

A constant that either specifies the kind of animation to perform when inserting the item or requests no animation. See SSCollectionViewItemAnimation in the header file for more.

Discussion

Note the behavior of this method when it is called in an animation block defined by the beginUpdates and endUpdates methods. SSCollectionView defers any insertions of items or sections until after it has handled the deletions of rows or sections. This happens regardless of ordering of the insertion and deletion method calls. This is unlike inserting or removing an item in a mutable array, where the operation can affect the array index used for the successive insertion or removal operation.

Currently, this is only supported inside of a beginUpdates and endUpdates animation block.

Declared In

SSCollectionView.h

deleteSections:withItemAnimation:

Deletes one or more sections in the receiver, with an option to animate the deletion.

- (void)deleteSections:(NSIndexSet *)sections withItemAnimation:(SSCollectionViewItemAnimation)animation

Parameters

sections

An index set that specifies the sections to insert in the receiving collection view. If a section already exists at the specified index location, it is moved down one index location.

animation

A constant that indicates how the insertion is to be animated, for example, fade in or slide in from the left. See SSCollectionViewItemAnimation in the header file for more.

Discussion

Note the behavior of this method when it is called in an animation block defined by the beginUpdates and endUpdates methods. SSCollectionView defers any insertions of items or sections until after it has handled the deletions of rows or sections. This happens regardless of ordering of the insertion and deletion method calls. This is unlike inserting or removing an item in a mutable array, where the operation can affect the array index used for the successive insertion or removal operation.

Currently, this is only supported inside of a beginUpdates and endUpdates animation block.

Declared In

SSCollectionView.h

dequeueReusableItemWithIdentifier:

Returns a reusable collection view item object located by its identifier.

- (SSCollectionViewItem *)dequeueReusableItemWithIdentifier:(NSString *)identifier

Parameters

identifier

A string identifying the item object to be reused.

Return Value

A SSCollectionViewItem object with the associated identifier or nil if no such object exists in the reusable-item queue.

Declared In

SSCollectionView.h

deselectItemAtIndexPath:animated:

Deselects a given item identified by index path, with an option to animate the deselection.

- (void)deselectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated

Parameters

indexPath

An index path identifying an item in the receiver.

animated

YES if you want to animate the deselection and NO if the change should be immediate.

Declared In

SSCollectionView.h

endUpdates

Conclude a series of method calls that insert, delete, select, or reload items and sections of the receiver.

- (void)endUpdates

Discussion

You call this method to bracket a series of method calls that began with beginUpdates and that consist of operations to insert, delete, select, and reload items and sections of the collection view. When you call endUpdates, SSCollectionView animates the operations simultaneously. Invocations of beginUpdates and endUpdates can be nested. If you do not make the insertion, deletion, and selection calls inside this block, collection view attributes such as item count might become invalid.

Currently only row-based animations are preformed. Eventually item-based animations will be supported.

See Also

Declared In

SSCollectionView.h

indexPathForItem:

Returns an index path representing the row (index) and section of a given collection view item.

- (NSIndexPath *)indexPathForItem:(SSCollectionViewItem *)item

Parameters

item

An item object of the collection view.

Return Value

An index path representing the row and section of the item or nil if the index path is invalid.

Declared In

SSCollectionView.h

indexPathsForVisibleRows

Returns an array of index paths each identifying a visible item in the receiver.

- (NSArray *)indexPathsForVisibleRows

Return Value

An array of NSIndexPath objects each representing a row index and section index that together identify a visible item in the collection view. Returns nil if no items are visible. The array’s order is undefined.

Declared In

SSCollectionView.h

insertItemsAtIndexPaths:withItemAnimation:

Inserts items in the receiver at the locations identified by an array of index paths, with an option to animate the insertion.

- (void)insertItemsAtIndexPaths:(NSArray *)indexPaths withItemAnimation:(SSCollectionViewItemAnimation)animation

Parameters

indexPaths

An array of NSIndexPath objects each representing a item index and section index that together identify an item in the collection view.

animation

A constant that either specifies the kind of animation to perform when inserting the item or requests no animation. See SSCollectionViewItemAnimation in the header file for more.

Discussion

Note the behavior of this method when it is called in an animation block defined by the beginUpdates and endUpdates methods. SSCollectionView defers any insertions of items or sections until after it has handled the deletions of rows or sections. This happens regardless of ordering of the insertion and deletion method calls. This is unlike inserting or removing an item in a mutable array, where the operation can affect the array index used for the successive insertion or removal operation.

Currently, this is only supported inside of a beginUpdates and endUpdates animation block.

Declared In

SSCollectionView.h

insertSections:withItemAnimation:

Inserts one or more sections in the receiver, with an option to animate the insertion.

- (void)insertSections:(NSIndexSet *)sections withItemAnimation:(SSCollectionViewItemAnimation)animation

Parameters

sections

An index set that specifies the sections to insert in the receiving collection view. If a section already exists at the specified index location, it is moved down one index location.

animation

A constant that indicates how the insertion is to be animated, for example, fade in or slide in from the left. See SSCollectionViewItemAnimation in the header file for more.

Discussion

Note the behavior of this method when it is called in an animation block defined by the beginUpdates and endUpdates methods. SSCollectionView defers any insertions of items or sections until after it has handled the deletions of rows or sections. This happens regardless of ordering of the insertion and deletion method calls. This is unlike inserting or removing an item in a mutable array, where the operation can affect the array index used for the successive insertion or removal operation.

Currently, this is only supported inside of a beginUpdates and endUpdates animation block.

Declared In

SSCollectionView.h

itemForIndexPath:

Returns the collection view item at the specified index path.

- (SSCollectionViewItem *)itemForIndexPath:(NSIndexPath *)indexPath

Parameters

indexPath

The index path locating the item in the receiver.

Return Value

An object representing an item of the collection or nil if the item is not visible or indexPath is out of range.

Declared In

SSCollectionView.h

numberOfItemsInSection:

Returns the number of item (collection view items) in a specified section.

- (NSUInteger)numberOfItemsInSection:(NSUInteger)section

Parameters

section

An index number that identifies a section of the collection.

Return Value

The number of items in the section.

Declared In

SSCollectionView.h

rectForFooterInSection:

Returns the drawing area for the footer of the specified section.

- (CGRect)rectForFooterInSection:(NSUInteger)section

Parameters

section

An index number identifying a section of the collection view.

Return Value

A rectangle defining the area in which the collection view draws the section footer.

Declared In

SSCollectionView.h

rectForHeaderInSection:

Returns the drawing area for the header of the specified section.

- (CGRect)rectForHeaderInSection:(NSUInteger)section

Parameters

section

An index number identifying a section of the collection view.

Return Value

A rectangle defining the area in which the collection view draws the section header.

Declared In

SSCollectionView.h

rectForSection:

Returns the drawing area for a specified section of the receiver.

- (CGRect)rectForSection:(NSUInteger)section

Parameters

section

An index number identifying a section of the collection view.

Return Value

A rectangle defining the area in which the collection view draws the section.

Declared In

SSCollectionView.h

reloadData

Reloads the items and sections of the receiver.

- (void)reloadData

Declared In

SSCollectionView.h

reloadItemsAtIndexPaths:

Reloads the specified item.

- (void)reloadItemsAtIndexPaths:(NSArray *)indexPaths

Parameters

indexPaths

An index path that identifies an item in the collection view by its row index and its section index.

Declared In

SSCollectionView.h

scrollToItemAtIndexPath:atScrollPosition:animated:

Scrolls the receiver until an item identified by index path is at a particular location on the screen.

- (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(SSCollectionViewScrollPosition)scrollPosition animated:(BOOL)animated

Parameters

indexPath

An index path that identifies an item in the table view by its row index and its section index.

scrollPosition

A constant that identifies a relative position in the receiving collection view (top, middle, bottom) for row when scrolling concludes.

animated

YES if you want to animate the change in position, NO if it should be immediate.

Declared In

SSCollectionView.h

selectItemAtIndexPath:animated:scrollPosition:

Selects an item in the receiver identified by index path, optionally scrolling the item to a location in the receiver.

- (void)selectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(SSCollectionViewScrollPosition)scrollPosition

Parameters

indexPath

An index path identifying an item in the receiver.

animated

YES if you want to animate the selection and any change in position, NO if the change should be immediate.

scrollPosition

A constant that identifies a relative position in the receiving collection view (top, middle, bottom) for the row when scrolling concludes.

Discussion

Calling this method does cause the delegate to receive a collectionView:willSelectRowAtIndexPath: and collectionView:didSelectRowAtIndexPath: message, which differs from UITableView.

Declared In

SSCollectionView.h

visibleItems

Returns the collection view items that are visible in the receiver.

- (NSArray *)visibleItems

Return Value

An array containing SSCollectionViewItem objects, each representing a visible item in the receiving collection view. The array’s order is undefined.

Declared In

SSCollectionView.h