NSIndexPath UIKit Additions

Inherits from
Conforms to
Framework
/System/Library/Frameworks/UIKit.framework
Availability
Available in iOS 2.0 and later.
Companion guide
Declared in
UICollectionView.h
UITableView.h

Overview

The UIKit framework adds programming interfaces to the NSIndexPath class of the Foundation framework to facilitate the identification of rows and sections in UITableView objects and the identification of items and sections in UICollectionView objects.

The API consists of class factory methods and properties for accessing the various indexed values. You use the factory methods to create an index path for the corresponding table view or collection view.

Tasks

Creating an Index Path Object

Getting the Section Index

Getting the Index of a Row or Item

Properties

item

An index number identifying an item in a section of a collection view. (read-only)

@property (nonatomic, readonly) NSInteger item;
Discussion

The section the item is in is identified by the value of section.

Availability
  • Available in iOS 6.0 and later.
Related Sample Code
Declared In
UICollectionView.h

row

An index number identifying a row in a section of a table view. (read-only)

@property(nonatomic, readonly) NSInteger row
Discussion

The section the row is in is identified by the value of section.

Availability
  • Available in iOS 2.0 and later.
Declared In
UITableView.h

section

An index number identifying a section in a table view or collection view. (read-only)

@property(nonatomic, readonly) NSInteger section
Availability
  • Available in iOS 2.0 and later.
Declared In
UITableView.h

Class Methods

indexPathForItem:inSection:

Returns an index-path object initialized with the indexes of a specific item and section in a collection view.

+ (NSIndexPath *)indexPathForItem:(NSInteger)item inSection:(NSInteger)section
Parameters
item

An index number identifying an item in a UICollectionView object in a section identified by the section parameter.

section

An index number identifying a section in a UICollectionView object.

Return Value

An NSIndexPath object or nil if the object could not be created.

Availability
  • Available in iOS 6.0 and later.
Declared In
UICollectionView.h

indexPathForRow:inSection:

Returns an index-path object initialized with the indexes of a specific row and section in a table view.

+ (NSIndexPath *)indexPathForRow:(NSInteger)row inSection:(NSInteger)section
Parameters
row

An index number identifying a row in a UITableView object in a section identified by section.

section

An index number identifying a section in a UITableView object.

Return Value

An NSIndexPath object or nil if the object could not be created.

Availability
  • Available in iOS 2.0 and later.
Declared In
UITableView.h