UITableView
An instance of UITableView (or simply, a table view) is a means for displaying and editing hierarchical lists of information.
A table view displays a list of items in a single column. UITableView is a subclass of UIScrollView, which allows users to scroll through the table, although UITableView allows vertical scrolling only. The cells comprising the individual items of the table are UITableViewCell objects; UITableView uses these objects to draw the visible rows of the table. Cells have content—titles and images—and can have, near the right edge, accessory views. Standard accessory views are disclosure indicators or detail disclosure buttons; the former leads to the next level in a data hierarchy and the latter leads to a detailed view of a selected item. Accessory views can also be framework controls, such as switches and sliders, or can be custom views. Table views can enter an editing mode where users can insert, delete, and reorder rows of the table.
A table view is made up of zero or more sections, each with its own rows. Sections are identified by their index number within the table view, and rows are identified by their index number within a section. Any section can optionally be preceded by a section header, and optionally be followed by a section footer.
Table views can have one of two styles, UITableViewStylePlain and UITableViewStyleGrouped. When you create a UITableView instance you must specify a table style, and this style cannot be changed. In the plain style, section headers and footers float above the content if the part of a complete section is visible. A table view can have an index that appears as a bar on the right hand side of the table (for example, "A" through "Z"). You can touch a particular label to jump to the target section. The grouped style of table view provides a default background color and a default background view for all cells. The background view provides a visual grouping for all cells in a particular section. For example, one group could be a person's name and title, another group for phone numbers that the person uses, and another group for email accounts and so on. See the Settings application for examples of grouped tables. Table views in the grouped style cannot have an index.
Many methods of UITableView take NSIndexPath objects as parameters and return values. UITableView declares a category on NSIndexPath that enables you to get the represented row index (row property) and section index (section property), and to construct an index path from a given row index and section index (indexPathForRow:inSection: method). Especially in table views with multiple sections, you must evaluate the section index before identifying a row by its index number.
A UITableView object must have an object that acts as a data source and an object that acts as a delegate; typically these objects are either the application delegate or, more frequently, a custom UITableViewController object. The data source must adopt the UITableViewDataSource protocol and the delegate must adopt the UITableViewDelegate protocol. The data source provides information that UITableView needs to construct tables and manages the data model when rows of a table are inserted, deleted, or reordered. The delegate manages table row configuration and selection, row reordering, highlighting, accessory views, and editing operations.
When sent a setEditing:animated: message (with a first parameter of YEStrue), the table view enters into editing mode where it shows the editing or reordering controls of each visible row, depending on the editingStyle of each associated UITableViewCell. Clicking on the insertion or deletion control causes the data source to receive a tableView:commitEditingStyle:forRowAtIndexPath: message. You commit a deletion or insertion by calling deleteRowsAtIndexPaths:withRowAnimation: or insertRowsAtIndexPaths:withRowAnimation:, as appropriate. Also in editing mode, if a table-view cell has its showsReorderControl property set to YEStrue, the data source receives a tableView:moveRowAtIndexPath:toIndexPath: message. The data source can selectively remove the reordering control for cells by implementing tableView:canMoveRowAtIndexPath:.
UITableView caches table-view cells for visible rows. You can create custom UITableViewCell objects with content or behavioral characteristics that are different than the default cells; A Closer Look at Table View Cells explains how.
UITableView overrides the layoutSubviews method of UIView so that it calls reloadData only when you create a new instance of UITableView or when you assign a new data source. Reloading the table view clears current state, including the current selection. However, if you explicitly call reloadData, it clears this state and any subsequent direct or indirect call to layoutSubviews does not trigger a reload.
For information about basic view behaviors, see View Programming Guide for iOS.
State Preservation
In iOS 6 and later, if you assign a value to a table view’s restorationIdentifier property, it attempts to preserve the currently selected rows and the first visible row. The table’s data source may adopt the UIDataSourceModelAssociation protocol, which provides a way to identify a row’s contents independent of that row’s position in the table. If the table’s data source adopts the UIDataSourceModelAssociation protocol, the data source will be consulted when saving state to convert the index paths for the top visible row and any selected cells to identifiers. During restoration, the data source will be consulted to convert those identifiers back to index paths and reestablish the top visible row, and reselect the cells. If the table’s data source does not implement the UIDataSourceModelAssociation protocol, the scroll position will be saved and restored directly, as will the index paths for selected cells.
For more information about how state preservation and restoration works, see App Programming Guide for iOS.
For more information about appearance and behavior configuration, see Table Views.
-
init(frame:style:) - initWithFrame:style:Designated InitializerInitializes and returns a table view object having the given frame and style.
Declaration
Swift
init(frameframe: CGRect, stylestyle: UITableViewStyle)Objective-C
- (instancetype)initWithFrame:(CGRect)framestyle:(UITableViewStyle)styleParameters
frameA rectangle specifying the initial location and size of the table view in its superview’s coordinates. The frame of the table view changes as table cells are added and deleted.
styleA constant that specifies the style of the table view. See Table View Style for descriptions of valid constants.
Return Value
Returns an initialized
UITableViewobject, ornilif the object could not be successfully initialized.Discussion
You must specify the style of a table view when you create it and you cannot thereafter modify the style. If you initialize the table view with the
UIViewmethodinitWithFrame:, theUITableViewStylePlainstyle is used as a default.Availability
Available in iOS 2.0 and later.
-
Returns the style of the table view. (read-only)
Declaration
Swift
var style: UITableViewStyle { get }Objective-C
@property(nonatomic, readonly) UITableViewStyle styleDiscussion
See Table View Style for descriptions of the constants used to specify table-view style.
Availability
Available in iOS 2.0 and later.
-
Returns the number of rows (table cells) in a specified section.
Declaration
Parameters
sectionAn index number that identifies a section of the table. Table views in a plain style have a section index of zero.
Return Value
The number of rows in the section.
Discussion
UITableViewgets the value returned by this method from its data source and caches it.Availability
Available in iOS 2.0 and later.
See Also
-
numberOfSections numberOfSectionsPropertyThe number of sections in the table view. (read-only)
Declaration
Swift
var numberOfSections: Int { get }Objective-C
@property(nonatomic, readonly) NSInteger numberOfSectionsDiscussion
UITableViewgets the value in this property from its data source and caches it.Availability
Available in iOS 2.0 and later.
See Also
-
The height of each row (that is, table cell) in the table view.
Discussion
Row height is expressed in points. You may set the row height for cells if the delegate doesn’t implement the
tableView:heightForRowAtIndexPath:method. The default value ofrowHeightisUITableViewAutomaticDimension. Note that if you create a self-sizing cell in Interface Builder, the default row height is changed to the value set in Interface Builder. To get the expected self-sizing behavior for a cell that you create in Interface Builder, you must explicitly setrowHeightequal toUITableViewAutomaticDimensionin your code.There are performance implications to using
tableView:heightForRowAtIndexPath:instead ofrowHeight. Every time a table view is displayed, it callstableView:heightForRowAtIndexPath:on the delegate for each of its rows, which can result in a significant performance problem with table views having a large number of rows (approximately 1000 or more).Availability
Available in iOS 2.0 and later.
-
separatorStyle separatorStylePropertyThe style for table cells used as separators.
Declaration
Swift
var separatorStyle: UITableViewCellSeparatorStyleObjective-C
@property(nonatomic) UITableViewCellSeparatorStyle separatorStyleDiscussion
The value of this property is one of the separator-style constants described in UITableViewCell Class Reference.
UITableViewuses this property to set the separator style on the cell returned from the delegate intableView:cellForRowAtIndexPath:.Availability
Available in iOS 2.0 and later.
See Also
-
separatorColor separatorColorProperty -
separatorEffect separatorEffectPropertyThe effect applied to table separators.
Declaration
Swift
@NSCopying var separatorEffect: UIVisualEffect?Objective-C
@property(nonatomic, copy) UIVisualEffect *separatorEffectAvailability
Available in iOS 8.0 and later.
-
backgroundView backgroundViewPropertyThe background view of the table view.
Declaration
Swift
var backgroundView: UIView?Objective-C
@property(nonatomic, strong) UIView *backgroundViewDiscussion
A table view’s background view is automatically resized to match the size of the table view. This view is placed as a subview of the table view behind all cells, header views, and footer views.
You must set this property to
nilto set the background color of the table view.Availability
Available in iOS 3.2 and later.
-
separatorInset separatorInsetPropertySpecifies the default inset of cell separators.
Declaration
Swift
var separatorInset: UIEdgeInsetsObjective-C
@property(nonatomic) UIEdgeInsets separatorInsetDiscussion
In iOS 7 and later, cell separators do not extend all the way to the edge of the table view. This property sets the default inset for all cells in the table, much as
rowHeightsets the default height for cells. It is also used for managing the “extra” separators drawn at the bottom of plain style tables.For example, to specify a table view where the default left separator inset is 3 points and the default right separator inset is 11, you would write:
tableView.separatorInset = UIEdgeInsetsMake(0, 3, 0, 11);
In a right-to-left user interface, an inset that you set using the
separatorInsetproperty automatically flips its left and right measurements.Special Considerations
Only left and right insets are honored. In a right-to-left user interface, the inset measurements are automatically flipped.
Availability
Available in iOS 7.0 and later.
-
A Boolean value that indicates whether the cell margins are derived from the width of the readable content guide.
Declaration
Swift
var cellLayoutMarginsFollowReadableWidth: BoolObjective-C
@property(nonatomic) BOOL cellLayoutMarginsFollowReadableWidthAvailability
Available in iOS 9.0 and later.
See Also
-
Registers a nib object containing a cell with the table view under a specified identifier.
Declaration
Parameters
nibA nib object that specifies the nib file to use to create the cell.
identifierThe reuse identifier for the cell. This parameter must not be
niland must not be an empty string.Discussion
Before dequeueing any cells, call this method or the
registerClass:forCellReuseIdentifier:method to tell the table view how to create new cells. If a cell of the specified type is not currently in a reuse queue, the table view uses the provided information to create a new cell object automatically.If you previously registered a class or nib file with the same reuse identifier, the nib you specify in the
nibparameter replaces the old entry. You may specifynilfornibif you want to unregister the nib from the specified reuse identifier.Availability
Available in iOS 5.0 and later.
See Also
tableView:cellForRowAtIndexPath:(UITableViewDataSource) -
Registers a class for use in creating new table cells.
Declaration
Objective-C
- (void)registerClass:(Class)cellClassforCellReuseIdentifier:(NSString *)identifierParameters
cellClassThe class of a cell that you want to use in the table.
identifierThe reuse identifier for the cell. This parameter must not be
niland must not be an empty string.Discussion
Prior to dequeueing any cells, call this method or the
registerNib:forCellReuseIdentifier:method to tell the table view how to create new cells. If a cell of the specified type is not currently in a reuse queue, the table view uses the provided information to create a new cell object automatically.If you previously registered a class or nib file with the same reuse identifier, the class you specify in the
cellClassparameter replaces the old entry. You may specifynilforcellClassif you want to unregister the class from the specified reuse identifier.Availability
Available in iOS 6.0 and later.
-
dequeueReusableCellWithIdentifier(_:forIndexPath:) - dequeueReusableCellWithIdentifier:forIndexPath:Returns a reusable table-view cell object for the specified reuse identifier and adds it to the table.
Declaration
Swift
func dequeueReusableCellWithIdentifier(_identifier: String, forIndexPathindexPath: NSIndexPath) -> UITableViewCellObjective-C
- (__kindofUITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifierforIndexPath:(NSIndexPath *)indexPathParameters
identifierA string identifying the cell object to be reused. This parameter must not be
nil.indexPathThe index path specifying the location of the cell. The data source receives this information when it is asked for the cell and should just pass it along. This method uses the index path to perform additional configuration based on the cell’s position in the table view.
Return Value
A
UITableViewCellobject with the associated reuse identifier. This method always returns a valid cell.Discussion
For performance reasons, a table view’s data source should generally reuse
UITableViewCellobjects when it assigns cells to rows in itstableView:cellForRowAtIndexPath:method. A table view maintains a queue or list ofUITableViewCellobjects that the data source has marked for reuse. Call this method from your data source object when asked to provide a new cell for the table view. This method dequeues an existing cell if one is available, or creates a new one based on the class or nib file you previously registered, and adds it to the table.If you registered a class for the specified
identifierand a new cell must be created, this method initializes the cell by calling itsinitWithStyle:reuseIdentifier:method. For nib-based cells, this method loads the cell object from the provided nib file. If an existing cell was available for reuse, this method calls the cell’sprepareForReusemethod instead.Availability
Available in iOS 6.0 and later.
-
Returns a reusable table-view cell object located by its identifier.
Declaration
Swift
func dequeueReusableCellWithIdentifier(_identifier: String) -> UITableViewCell?Objective-C
- (__kindofUITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifierParameters
identifierA string identifying the cell object to be reused. This parameter must not be
nil.Return Value
A
UITableViewCellobject with the associatedidentifierornilif no such object exists in the reusable-cell queue.Discussion
For performance reasons, a table view’s data source should generally reuse
UITableViewCellobjects when it assigns cells to rows in itstableView:cellForRowAtIndexPath:method. A table view maintains a queue or list ofUITableViewCellobjects that the data source has marked for reuse. Call this method from your data source object when asked to provide a new cell for the table view. This method dequeues an existing cell if one is available or creates a new one using the class or nib file you previously registered. If no cell is available for reuse and you did not register a class or nib file, this method returnsnil.If you registered a class for the specified
identifierand a new cell must be created, this method initializes the cell by calling itsinitWithStyle:reuseIdentifier:method. For nib-based cells, this method loads the cell object from the provided nib file. If an existing cell was available for reuse, this method calls the cell’sprepareForReusemethod instead.Availability
Available in iOS 2.0 and later.
-
registerNib(_:forHeaderFooterViewReuseIdentifier:) - registerNib:forHeaderFooterViewReuseIdentifier:Registers a nib object containing a header or footer with the table view under a specified identifier.
Declaration
Parameters
nibA nib object that specifies the nib file to use to create the header or footer view. This parameter cannot be
nil.identifierThe reuse identifier for the header or footer view. This parameter must not be
niland must not be an empty string.Discussion
Before dequeueing any header or footer views, call this method or the
registerClass:forHeaderFooterViewReuseIdentifier:method to tell the table view how to create new instances of your views. If a view of the specified type is not currently in a reuse queue, the table view uses the provided information to create a new one automatically.If you previously registered a class or nib file with the same reuse identifier, the nib you specify in the
nibparameter replaces the old entry. You may specifynilfornibif you want to unregister the nib from the specified reuse identifier.Availability
Available in iOS 6.0 and later.
-
registerClass(_:forHeaderFooterViewReuseIdentifier:) - registerClass:forHeaderFooterViewReuseIdentifier:Registers a class for use in creating new table header or footer views.
Declaration
Swift
func registerClass(_aClass: AnyClass?, forHeaderFooterViewReuseIdentifieridentifier: String)Objective-C
- (void)registerClass:(Class)aClassforHeaderFooterViewReuseIdentifier:(NSString *)identifierParameters
aClassThe class of a header or footer view that you want to use in the table.
identifierThe reuse identifier for the header or footer view. This parameter must not be
niland must not be an empty string.Discussion
Before dequeueing any header or footer views, call this method or the
registerNib:forHeaderFooterViewReuseIdentifier:method to tell the table view how to create new instances of your views. If a view of the specified type is not currently in a reuse queue, the table view uses the provided information to create a one automatically.If you previously registered a class or nib file with the same reuse identifier, the class you specify in the
aClassparameter replaces the old entry. You may specifynilforaClassif you want to unregister the class from the specified reuse identifier.Availability
Available in iOS 6.0 and later.
-
Returns a reusable header or footer view located by its identifier.
Declaration
Swift
func dequeueReusableHeaderFooterViewWithIdentifier(_identifier: String) -> UITableViewHeaderFooterView?Objective-C
- (__kindofUITableViewHeaderFooterView *)dequeueReusableHeaderFooterViewWithIdentifier:(NSString *)identifierParameters
identifierA string identifying the header or footer view to be reused. This parameter must not be
nil.Return Value
A
UITableViewHeaderFooterViewobject with the associated identifier ornilif no such object exists in the reusable view queue.Discussion
For performance reasons, a table view’s delegate should generally reuse
UITableViewHeaderFooterViewobjects when it is asked to provide them. A table view maintains a queue or list ofUITableViewHeaderFooterViewobjects that the table view's delegate has marked for reuse. It marks a view for reuse by assigning it a reuse identifier when it creates it (that is, in theinitWithReuseIdentifier:method ofUITableViewHeaderFooterView).You can use this method to access specific template header and footer views that you previously created. You can access a view’s reuse identifier through its
reuseIdentifierproperty.Availability
Available in iOS 6.0 and later.
-
tableHeaderView tableHeaderViewPropertyReturns an accessory view that is displayed above the table.
Declaration
Swift
var tableHeaderView: UIView?Objective-C
@property(nonatomic, strong) UIView *tableHeaderViewDiscussion
The default value is
nil. The table header view is different from a section header.Availability
Available in iOS 2.0 and later.
See Also
-
tableFooterView tableFooterViewPropertyReturns an accessory view that is displayed below the table.
Declaration
Swift
var tableFooterView: UIView?Objective-C
@property(nonatomic, strong) UIView *tableFooterViewDiscussion
The default value is
nil. The table footer view is different from a section footer.Availability
Available in iOS 2.0 and later.
See Also
-
sectionHeaderHeight sectionHeaderHeightPropertyThe height of section headers in the table view.
Declaration
Swift
var sectionHeaderHeight: CGFloatObjective-C
@property(nonatomic) CGFloat sectionHeaderHeightDiscussion
This nonnegative value is used only if the delegate doesn’t implement the
tableView:heightForHeaderInSection:method.Availability
Available in iOS 2.0 and later.
See Also
-
sectionFooterHeight sectionFooterHeightPropertyThe height of section footers in the table view.
Declaration
Swift
var sectionFooterHeight: CGFloatObjective-C
@property(nonatomic) CGFloat sectionFooterHeightDiscussion
This nonnegative value is used only in section group tables and only if the delegate doesn't implement the
tableView:heightForFooterInSection:method.Availability
Available in iOS 2.0 and later.
See Also
-
Returns the header view associated with the specified section.
Declaration
Swift
func headerViewForSection(_section: Int) -> UITableViewHeaderFooterView?Objective-C
- (UITableViewHeaderFooterView *)headerViewForSection:(NSInteger)sectionParameters
sectionAn index number that identifies a section of the table. Table views in a plain style have a section index of zero.
Return Value
The header view associated with the section, or
nilif the section does not have a header view.Availability
Available in iOS 6.0 and later.
-
Returns the footer view associated with the specified section.
Declaration
Swift
func footerViewForSection(_section: Int) -> UITableViewHeaderFooterView?Objective-C
- (UITableViewHeaderFooterView *)footerViewForSection:(NSInteger)sectionParameters
sectionAn index number that identifies a section of the table. Table views in a plain style have a section index of zero.
Return Value
The footer view associated with the section, or
nilif the section does not have a footer view.Availability
Available in iOS 6.0 and later.
-
Returns the table cell at the specified index path.
Declaration
Swift
func cellForRowAtIndexPath(_indexPath: NSIndexPath) -> UITableViewCell?Objective-C
- (__kindofUITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPathParameters
indexPathThe index path locating the row in the table view.
Return Value
An object representing a cell of the table, or
nilif the cell is not visible orindexPathis out of range.Availability
Available in iOS 2.0 and later.
See Also
-
Returns an index path representing the row and section of a given table-view cell.
Declaration
Swift
func indexPathForCell(_cell: UITableViewCell) -> NSIndexPath?Objective-C
- (NSIndexPath *)indexPathForCell:(UITableViewCell *)cellParameters
cellA cell object of the table view.
Return Value
An index path representing the row and section of the cell, or
nilif the index path is invalid.Availability
Available in iOS 2.0 and later.
See Also
-
Returns an index path identifying the row and section at the given point.
Declaration
Swift
func indexPathForRowAtPoint(_point: CGPoint) -> NSIndexPath?Objective-C
- (NSIndexPath *)indexPathForRowAtPoint:(CGPoint)pointParameters
pointA point in the local coordinate system of the table view (the table view’s bounds).
Return Value
An index path representing the row and section associated with
point, ornilif the point is out of the bounds of any row.Availability
Available in iOS 2.0 and later.
See Also
-
An array of index paths each representing a row enclosed by a given rectangle.
Declaration
Swift
func indexPathsForRowsInRect(_rect: CGRect) -> [NSIndexPath]?Objective-C
- (NSArray<NSIndexPath *> *)indexPathsForRowsInRect:(CGRect)rectParameters
rectA rectangle defining an area of the table view in local coordinates.
Return Value
An array of
NSIndexPathobjects each representing a row and section index identifying a row withinrect. Returns an empty array if there aren’t any rows to return.Availability
Available in iOS 2.0 and later.
See Also
-
visibleCells visibleCellsPropertyThe table cells that are visible in the table view. (read-only)
Declaration
Swift
var visibleCells: [UITableViewCell] { get }Objective-C
@property(nonatomic, readonly) NSArray <__kindof UITableViewCell *> *visibleCellsDiscussion
The value of this property is an array containing
UITableViewCellobjects, each representing a visible cell in the table view.Availability
Available in iOS 2.0 and later.
See Also
-
An array of index paths each identifying a visible row in the table view. (read-only)
Declaration
Swift
var indexPathsForVisibleRows: [NSIndexPath]? { get }Objective-C
@property(nonatomic, readonly) NSArray <NSIndexPath *> *indexPathsForVisibleRowsDiscussion
The value of this property is an array of
NSIndexPathobjects each representing a row index and section index that together identify a visible row in the table view. If no rows are visible, the value isnil.Availability
Available in iOS 2.0 and later.
See Also
-
estimatedRowHeight estimatedRowHeightPropertyThe estimated height of rows in the table view.
Declaration
Swift
var estimatedRowHeight: CGFloatObjective-C
@property(nonatomic) CGFloat estimatedRowHeightDiscussion
Providing a nonnegative estimate of the height of rows can improve the performance of loading the table view. If the table contains variable height rows, it might be expensive to calculate all their heights when the table loads. Using estimation allows you to defer some of the cost of geometry calculation from load time to scrolling time.
When you create a self-sizing table view cell, you need to set this property and use constraints to define the cell’s size.
The default value is
0, which means there is no estimate.Availability
Available in iOS 7.0 and later.
-
The estimated height of section headers in the table view.
Declaration
Swift
var estimatedSectionHeaderHeight: CGFloatObjective-C
@property(nonatomic) CGFloat estimatedSectionHeaderHeightDiscussion
Providing a nonnegative estimate of the height of section headers can improve the performance of loading the table view. If the table contains variable height section headers, it might be expensive to calculate all their heights when the table loads. Using estimation allows you to defer some of the cost of geometry calculation from load time to scrolling time.
The default value is
0, which means there is no estimate.Availability
Available in iOS 7.0 and later.
-
The estimated height of section footers in the table view.
Declaration
Swift
var estimatedSectionFooterHeight: CGFloatObjective-C
@property(nonatomic) CGFloat estimatedSectionFooterHeightDiscussion
Providing a nonnegative estimate of the height of section footers can improve the performance of loading the table view. If the table contains variable height section footers, it might be expensive to calculate all their heights when the table loads. Using estimation allows you to defer some of the cost of geometry calculation from load time to scrolling time.
The default value is
0, which means there is no estimate.Availability
Available in iOS 7.0 and later.
-
scrollToRowAtIndexPath(_:atScrollPosition:animated:) - scrollToRowAtIndexPath:atScrollPosition:animated:Scrolls through the table view until a row identified by index path is at a particular location on the screen.
Declaration
Swift
func scrollToRowAtIndexPath(_indexPath: NSIndexPath, atScrollPositionscrollPosition: UITableViewScrollPosition, animatedanimated: Bool)Objective-C
- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPathatScrollPosition:(UITableViewScrollPosition)scrollPositionanimated:(BOOL)animatedParameters
indexPathAn index path that identifies a row in the table view by its row index and its section index.
NSNotFoundis a valid row index for scrolling to a section with zero rows.scrollPositionA constant that identifies a relative position in the table view (top, middle, bottom) for
rowwhen scrolling concludes. See Table View Scroll Position for descriptions of valid constants.animatedYEStrueif you want to animate the change in position;NOfalseif it should be immediate.Discussion
Invoking this method does not cause the delegate to receive a
scrollViewDidScroll:message, as is normal for programmatically invoked user interface operations.Availability
Available in iOS 2.0 and later.
-
scrollToNearestSelectedRowAtScrollPosition(_:animated:) - scrollToNearestSelectedRowAtScrollPosition:animated:Scrolls the table view so that the selected row nearest to a specified position in the table view is at that position.
Declaration
Swift
func scrollToNearestSelectedRowAtScrollPosition(_scrollPosition: UITableViewScrollPosition, animatedanimated: Bool)Objective-C
- (void)scrollToNearestSelectedRowAtScrollPosition:(UITableViewScrollPosition)scrollPositionanimated:(BOOL)animatedParameters
scrollPositionA constant that identifies a relative position in the table view (top, middle, bottom) for the row when scrolling concludes. See Table View Scroll Position for a descriptions of valid constants.
animatedYEStrueif you want to animate the change in position;NOfalseif it should be immediate.Availability
Available in iOS 2.0 and later.
-
An index path identifying the row and section of the selected row. (read-only)
Declaration
Swift
var indexPathForSelectedRow: NSIndexPath? { get }Objective-C
@property(nonatomic, readonly) NSIndexPath *indexPathForSelectedRowDiscussion
The value of this property is an index path identifying the row and section indexes of the selected row, or
nilif the index path is invalid. If there are multiple selections, this property contains the first index-path object in the array of row selections; this object has the lowest index values for section and row.Availability
Available in iOS 2.0 and later.
-
The index paths representing the selected rows. (read-only)
Declaration
Swift
var indexPathsForSelectedRows: [NSIndexPath]? { get }Objective-C
@property(nonatomic, readonly) NSArray <NSIndexPath *> *indexPathsForSelectedRowsDiscussion
The value of this property is an array of index-path objects each identifying a row through its section and row index. The value of this property is
nilif there are no selected rows.Availability
Available in iOS 5.0 and later.
See Also
-
Selects a row in the table view identified by index path, optionally scrolling the row to a location in the table view.
Declaration
Swift
func selectRowAtIndexPath(_indexPath: NSIndexPath?, animatedanimated: Bool, scrollPositionscrollPosition: UITableViewScrollPosition)Objective-C
- (void)selectRowAtIndexPath:(NSIndexPath *)indexPathanimated:(BOOL)animatedscrollPosition:(UITableViewScrollPosition)scrollPositionParameters
indexPathAn index path identifying a row in the table view.
animatedYEStrueif you want to animate the selection and any change in position;NOfalseif the change should be immediate.scrollPositionA constant that identifies a relative position in the table view (top, middle, bottom) for the row when scrolling concludes. See Table View Scroll Position for descriptions of valid constants.
Discussion
Calling this method does not cause the delegate to receive a
tableView:willSelectRowAtIndexPath:ortableView:didSelectRowAtIndexPath:message, nor does it sendUITableViewSelectionDidChangeNotificationnotifications to observers.Special Considerations
Passing
UITableViewScrollPositionNoneresults in no scrolling, rather than the minimum scrolling described for that constant. To scroll to the newly selected row with minimum scrolling, select the row using this method withUITableViewScrollPositionNone, then callscrollToRowAtIndexPath:atScrollPosition:animated:withUITableViewScrollPositionNone.NSIndexPath *rowToSelect; // assume this exists and is set properlyUITableView *myTableView; // assume this exists[myTableView selectRowAtIndexPath:rowToSelect animated:YES scrollPosition:UITableViewScrollPositionNone];[myTableView scrollToRowAtIndexPath:rowToSelect atScrollPosition:UITableViewScrollPositionNone animated:YES];
Availability
Available in iOS 2.0 and later.
See Also
-
Deselects a given row identified by index path, with an option to animate the deselection.
Declaration
Swift
func deselectRowAtIndexPath(_indexPath: NSIndexPath, animatedanimated: Bool)Objective-C
- (void)deselectRowAtIndexPath:(NSIndexPath *)indexPathanimated:(BOOL)animatedParameters
indexPathAn index path identifying a row in the table view.
animatedYEStrueif you want to animate the deselection, andNOfalseif the change should be immediate.Discussion
Calling this method does not cause the delegate to receive a
tableView:willDeselectRowAtIndexPath:ortableView:didDeselectRowAtIndexPath:message, nor does it sendUITableViewSelectionDidChangeNotificationnotifications to observers.Calling this method does not cause any scrolling to the deselected row.
Availability
Available in iOS 2.0 and later.
See Also
-
allowsSelection allowsSelectionPropertyA Boolean value that determines whether users can select a row.
Discussion
If the value of this property is
YEStrue(the default), users can select rows. If you set it toNOfalse, they cannot select rows. Setting this property affects cell selection only when the table view is not in editing mode. If you want to restrict selection of cells in editing mode, useallowsSelectionDuringEditing.Availability
Available in iOS 3.0 and later.
-
A Boolean value that determines whether users can select more than one row outside of editing mode.
Declaration
Swift
var allowsMultipleSelection: BoolObjective-C
@property(nonatomic) BOOL allowsMultipleSelectionDiscussion
This property controls whether multiple rows can be selected simultaneously outside of editing mode. When the value of this property is
YEStrue, each row that is tapped acquires a selected appearance. Tapping the row again removes the selected appearance. If you accessindexPathsForSelectedRows, you can get the index paths that identify the selected rows.The default value of this property is
NOfalse.Availability
Available in iOS 5.0 and later.
-
A Boolean value that determines whether users can select cells while the table view is in editing mode.
Declaration
Swift
var allowsSelectionDuringEditing: BoolObjective-C
@property(nonatomic) BOOL allowsSelectionDuringEditingDiscussion
If the value of this property is
YEStrue, users can select rows during editing. The default value isNOfalse. If you want to restrict selection of cells regardless of mode, useallowsSelection.Availability
Available in iOS 2.0 and later.
-
A Boolean value that controls whether users can select more than one cell simultaneously in editing mode.
Declaration
Swift
var allowsMultipleSelectionDuringEditing: BoolObjective-C
@property(nonatomic) BOOL allowsMultipleSelectionDuringEditingDiscussion
The default value of this property is
NOfalse. If you set it toYEStrue, check marks appear next to selected rows in editing mode. In addition,UITableViewdoes not query for editing styles when it goes into editing mode. If you accessindexPathsForSelectedRows, you can get the index paths that identify the selected rows.Availability
Available in iOS 5.0 and later.
-
Begins a series of method calls that insert, delete, or select rows and sections of the table view.
Declaration
Swift
func beginUpdates()Objective-C
- (void)beginUpdatesDiscussion
Call this method if you want subsequent insertions, deletion, and selection operations (for example,
cellForRowAtIndexPath:andindexPathsForVisibleRows) to be animated simultaneously. You can also use this method followed by theendUpdatesmethod to animate the change in the row heights without reloading the cell. This group of methods must conclude with an invocation ofendUpdates. These method pairs can be nested. If you do not make the insertion, deletion, and selection calls inside this block, table attributes such as row count might become invalid. You should not callreloadDatawithin the group; if you call this method within the group, you must perform any animations yourself.Availability
Available in iOS 2.0 and later.
-
Concludes a series of method calls that insert, delete, select, or reload rows and sections of the table view.
Declaration
Swift
func endUpdates()Objective-C
- (void)endUpdatesDiscussion
You call this method to bracket a series of method calls that begins with
beginUpdatesand that consists of operations to insert, delete, select, and reload rows and sections of the table view. When you callendUpdates,UITableViewanimates the operations simultaneously. Invocations ofbeginUpdatesandendUpdatescan be nested. If you do not make the insertion, deletion, and selection calls inside this block, table attributes such as row count can become invalid.Availability
Available in iOS 2.0 and later.
-
Inserts rows in the table view at the locations identified by an array of index paths, with an option to animate the insertion.
Declaration
Swift
func insertRowsAtIndexPaths(_indexPaths: [NSIndexPath], withRowAnimationanimation: UITableViewRowAnimation)Objective-C
- (void)insertRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPathswithRowAnimation:(UITableViewRowAnimation)animationParameters
indexPathsAn array of
NSIndexPathobjects, each representing a row index and section index that together identify a row in the table view.animationA constant that either specifies the kind of animation to perform when inserting the cell or requests no animation. See Table Cell Insertion and Deletion Animation for descriptions of the constants.
Discussion
UITableViewcalls the relevant delegate and data source methods immediately afterward to get the cells and other content for visible cells.When this method when is called in an animation block defined by the
beginUpdatesandendUpdatesmethods,UITableViewdefers any insertions of rows or sections until after it has handled the deletions of rows or sections. This order is followed regardless of how the insertion and deletion method calls are ordered. This is unlike inserting or removing an item in a mutable array, in which the operation can affect the array index used for the successive insertion or removal operation. For more on this subject, see Batch Insertion, Deletion, and Reloading of Rows and Sections in Table View Programming Guide for iOS.Availability
Available in iOS 2.0 and later.
-
Deletes the rows specified by an array of index paths, with an option to animate the deletion.
Declaration
Swift
func deleteRowsAtIndexPaths(_indexPaths: [NSIndexPath], withRowAnimationanimation: UITableViewRowAnimation)Objective-C
- (void)deleteRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPathswithRowAnimation:(UITableViewRowAnimation)animationParameters
indexPathsAn array of
NSIndexPathobjects identifying the rows to delete.animationA constant that indicates how the deletion is to be animated, for example, fade out or slide out from the bottom. See Table Cell Insertion and Deletion Animation for descriptions of these constants.
Discussion
When this method is called in an animation block defined by the
beginUpdatesandendUpdatesmethods,UITableViewdefers any insertions of rows or sections until after it has handled the deletions of rows or sections. This order is followed regardless how the insertion and deletion method calls are ordered. This is unlike inserting or removing an item in a mutable array, in which the operation can affect the array index used for the successive insertion or removal operation. For more on this subject, see Batch Insertion, Deletion, and Reloading of Rows and Sections in Table View Programming Guide for iOS.Availability
Available in iOS 2.0 and later.
-
Moves the row at a specified location to a destination location.
Declaration
Swift
func moveRowAtIndexPath(_indexPath: NSIndexPath, toIndexPathnewIndexPath: NSIndexPath)Objective-C
- (void)moveRowAtIndexPath:(NSIndexPath *)indexPathtoIndexPath:(NSIndexPath *)newIndexPathParameters
indexPathAn index path identifying the row to move.
newIndexPathAn index path identifying the row that is the destination of the row at
indexPath. The existing row at that location slides up or down to an adjoining index position to make room for it.Discussion
You can combine row-move operations with row-insertion and row-deletion operations within a
beginUpdates–endUpdatesblock to have all changes occur together as a single animation.Unlike the row-insertion and row-deletion methods, this method does not take an
animationparameter. For rows that are moved, the moved row animates straight from the starting position to the ending position. Also unlike the other methods, this method allows only one row to be moved per call. If you want multiple rows moved, you can call this method repeatedly within abeginUpdates–endUpdatesblock.Availability
Available in iOS 5.0 and later.
-
Inserts one or more sections in the table view, with an option to animate the insertion.
Declaration
Swift
func insertSections(_sections: NSIndexSet, withRowAnimationanimation: UITableViewRowAnimation)Objective-C
- (void)insertSections:(NSIndexSet *)sectionswithRowAnimation:(UITableViewRowAnimation)animationParameters
sectionsAn index set that specifies the sections to insert in the table view. If a section already exists at the specified index location, it is moved down one index location.
animationA constant that indicates how the insertion is to be animated, for example, fade in or slide in from the left. See Table Cell Insertion and Deletion Animation for descriptions of these constants.
Discussion
UITableViewcalls the relevant delegate and data source methods immediately afterward to get the cells and other content for visible cells.When this method is called in an animation block defined by the
beginUpdatesandendUpdatesmethods,UITableViewdefers any insertions of rows or sections until after it has handled the deletions of rows or sections. This order is followed regardless of how the insertion and deletion method calls are ordered. This is unlike inserting or removing an item in a mutable array, in which the operation can affect the array index used for the successive insertion or removal operation. For more on this subject, see Batch Insertion, Deletion, and Reloading of Rows and Sections in Table View Programming Guide for iOS.Availability
Available in iOS 2.0 and later.
-
Deletes one or more sections in the table view, with an option to animate the deletion.
Declaration
Swift
func deleteSections(_sections: NSIndexSet, withRowAnimationanimation: UITableViewRowAnimation)Objective-C
- (void)deleteSections:(NSIndexSet *)sectionswithRowAnimation:(UITableViewRowAnimation)animationParameters
sectionsAn index set that specifies the sections to delete from the table view. If a section exists after the specified index location, it is moved up one index location.
animationA constant that either specifies the kind of animation to perform when deleting the section or requests no animation. See Table Cell Insertion and Deletion Animation for descriptions of the constants.
Discussion
When this method when is called in an animation block defined by the
beginUpdatesandendUpdatesmethods,UITableViewdefers any insertions of rows or sections until after it has handled the deletions of rows or sections. This order is followed regardless how the insertion and deletion method calls are ordered. This is unlike inserting or removing an item in a mutable array, in which the operation can affect the array index used for the successive insertion or removal operation. For more on this subject, see Batch Insertion, Deletion, and Reloading of Rows and Sections in Table View Programming Guide for iOS.Availability
Available in iOS 2.0 and later.
-
Moves a section to a new location in the table view.
Declaration
Parameters
sectionThe index of the section to move.
newSectionThe index in the table view that is the destination of the move for the section. The existing section at that location slides up or down to an adjoining index position to make room for it.
Discussion
You can combine section-move operations with section-insertion and section-deletion operations within a
beginUpdates–endUpdatesblock to have all changes occur together as a single animation.Unlike the section-insertion section row-deletion methods, this method does not take an animation parameter. For sections that are moved, the moved section animates straight from the starting position to the ending position. Also unlike the other methods, this method allows only one section to be moved per call. If you want multiple section moved, call this method repeatedly within a
beginUpdates–endUpdatesblock.Availability
Available in iOS 5.0 and later.
-
A Boolean value that determines whether the table view is in editing mode.
Discussion
When the value of this property is
YEStrue, the table view is in editing mode: The cells of the table might show an insertion or deletion control on the left side of each cell and a reordering control on the right side, depending on how the cell is configured. (See UITableViewCell Class Reference for details.) Tapping a control causes the table view to invoke the data source methodtableView:commitEditingStyle:forRowAtIndexPath:. The default value isNOfalse.Availability
Available in iOS 2.0 and later.
See Also
-
Toggles the table view into and out of editing mode.
Declaration
Objective-C
- (void)setEditing:(BOOL)editinganimated:(BOOL)animateParameters
editingYEStrueto enter editing mode;NOfalseto leave it. The default value isNOfalse.animateYEStrueto animate the transition to editing mode;NOfalseto make the transition immediate.Discussion
When you call this method with the value of
editingset toYEStrue, the table view goes into editing mode by callingsetEditing:animated:on each visibleUITableViewCellobject. Calling this method witheditingset toNOfalseturns off editing mode. In editing mode, the cells of the table might show an insertion or deletion control on the left side of each cell and a reordering control on the right side, depending on how the cell is configured. (See UITableViewCell Class Reference for details.) The data source of the table view can selectively exclude cells from editing mode by implementingtableView:canEditRowAtIndexPath:.Availability
Available in iOS 2.0 and later.
See Also
-
Reloads the rows and sections of the table view.
Declaration
Swift
func reloadData()Objective-C
- (void)reloadDataDiscussion
Call this method to reload all the data that is used to construct the table, including cells, section headers and footers, index arrays, and so on. For efficiency, the table view redisplays only those rows that are visible. It adjusts offsets if the table shrinks as a result of the reload. The table view’s delegate or data source calls this method when it wants the table view to completely reload its data. It should not be called in the methods that insert or delete rows, especially within an animation block implemented with calls to
beginUpdatesandendUpdates.Availability
Available in iOS 2.0 and later.
-
Reloads the specified rows using an animation effect.
Declaration
Swift
func reloadRowsAtIndexPaths(_indexPaths: [NSIndexPath], withRowAnimationanimation: UITableViewRowAnimation)Objective-C
- (void)reloadRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPathswithRowAnimation:(UITableViewRowAnimation)animationParameters
indexPathsAn array of
NSIndexPathobjects identifying the rows to reload.animationA constant that indicates how the reloading is to be animated, for example, fade out or slide out from the bottom. See Table Cell Insertion and Deletion Animation for descriptions of these constants.
The animation constant affects the direction in which both the old and the new rows slide. For example, if the animation constant is
UITableViewRowAnimationRight, the old rows slide out to the right and the new cells slide in from the right.Discussion
Reloading a row causes the table view to ask its data source for a new cell for that row. The table animates that new cell in as it animates the old row out. Call this method if you want to alert the user that the value of a cell is changing. If, however, notifying the user is not important—that is, you just want to change the value that a cell is displaying—you can get the cell for a particular row and set its new value.
When this method is called in an animation block defined by the
beginUpdatesandendUpdatesmethods, it behaves similarly todeleteRowsAtIndexPaths:withRowAnimation:. The indexes thatUITableViewpasses to the method are specified in the state of the table view prior to any updates. This happens regardless of ordering of the insertion, deletion, and reloading method calls within the animation block.Availability
Available in iOS 3.0 and later.
-
Reloads the specified sections using a given animation effect.
Declaration
Swift
func reloadSections(_sections: NSIndexSet, withRowAnimationanimation: UITableViewRowAnimation)Objective-C
- (void)reloadSections:(NSIndexSet *)sectionswithRowAnimation:(UITableViewRowAnimation)animationParameters
sectionsAn index set identifying the sections to reload.
animationA constant that indicates how the reloading is to be animated, for example, fade out or slide out from the bottom. See Table Cell Insertion and Deletion Animation for descriptions of these constants.
The animation constant affects the direction in which both the old and the new section rows slide. For example, if the animation constant is
UITableViewRowAnimationRight, the old rows slide out to the right and the new cells slide in from the right.Discussion
Calling this method causes the table view to ask its data source for new cells for the specified sections. The table view animates the insertion of new cells in as it animates the old cells out. Call this method if you want to alert the user that the values of the designated sections are changing. If, however, you just want to change values in cells of the specified sections without alerting the user, you can get those cells and directly set their new values.
When this method is called in an animation block defined by the
beginUpdatesandendUpdatesmethods, it behaves similarly todeleteSections:withRowAnimation:. The indexes thatUITableViewpasses to the method are specified in the state of the table view prior to any updates. This happens regardless of ordering of the insertion, deletion, and reloading method calls within the animation block.Availability
Available in iOS 3.0 and later.
See Also
-
Reloads the items in the index bar along the right side of the table view.
Declaration
Swift
func reloadSectionIndexTitles()Objective-C
- (void)reloadSectionIndexTitlesDiscussion
This method gives you a way to update the section index after inserting or deleting sections without having to reload the whole table.
Availability
Available in iOS 3.0 and later.
See Also
sectionIndexTitlesForTableView:(UITableViewDataSource)
-
Returns the drawing area for a specified section of the table view.
Declaration
Parameters
sectionAn index number identifying a section of the table view. Plain-style table views always have a section index of zero.
Return Value
A rectangle defining the area in which the table view draws the section.
Availability
Available in iOS 2.0 and later.
-
Returns the drawing area for a row identified by index path.
Declaration
Swift
func rectForRowAtIndexPath(_indexPath: NSIndexPath) -> CGRectObjective-C
- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPathParameters
indexPathAn index path object that identifies a row by its index and its section index.
Return Value
A rectangle defining the area in which the table view draws the row or
CGRectZeroifindexPathis invalid.Availability
Available in iOS 2.0 and later.
-
Returns the drawing area for the footer of the specified section.
Declaration
Parameters
sectionAn index number identifying a section of the table view. Plain-style table views always have a section index of zero.
Return Value
A rectangle defining the area in which the table view draws the section footer.
Availability
Available in iOS 2.0 and later.
-
Returns the drawing area for the header of the specified section.
Declaration
Parameters
sectionAn index number identifying a section of the table view. Plain-style table views always have a section index of zero.
Return Value
A rectangle defining the area in which the table view draws the section header.
Availability
Available in iOS 2.0 and later.
-
dataSource dataSourcePropertyThe object that acts as the data source of the table view.
Declaration
Swift
weak var dataSource: UITableViewDataSource?Objective-C
@property(nonatomic, weak) id< UITableViewDataSource > dataSourceDiscussion
The data source must adopt the
UITableViewDataSourceprotocol. The data source is not retained.Availability
Available in iOS 2.0 and later.
See Also
-
The object that acts as the delegate of the table view.
Declaration
Swift
weak var delegate: UITableViewDelegate?Objective-C
@property(nonatomic, weak) id< UITableViewDelegate > delegateDiscussion
The delegate must adopt the
UITableViewDelegateprotocol. The delegate is not retained.Availability
Available in iOS 2.0 and later.
See Also
-
The number of table rows at which to display the index list on the right edge of the table.
Declaration
Swift
var sectionIndexMinimumDisplayRowCount: IntObjective-C
@property(nonatomic) NSInteger sectionIndexMinimumDisplayRowCountDiscussion
This property is applicable only to table views in the
UITableViewStylePlainstyle. The default value is zero.Availability
Available in iOS 2.0 and later.
-
sectionIndexColor sectionIndexColorPropertyThe color to use for the table view’s index text.
Declaration
Swift
var sectionIndexColor: UIColor?Objective-C
@property(nonatomic, strong) UIColor *sectionIndexColorDiscussion
Table views can display an index along the side of the view, making it easier for users to navigate the contents of the table quickly. This property specifies the color to use for text displayed in this region. A value of
nilrepresents the default color.Availability
Available in iOS 6.0 and later.
-
The color to use for the background of the table view’s section index while not being touched.
Declaration
Swift
var sectionIndexBackgroundColor: UIColor?Objective-C
@property(nonatomic, strong) UIColor *sectionIndexBackgroundColorDiscussion
Table views can display an index along the side of the view, making it easier for users to navigate the contents of the table quickly. This property specifies the color to use for the background of the index. A value of
nilrepresents the default color.Availability
Available in iOS 7.0 and later.
-
The color to use for the table view’s index background area.
Declaration
Swift
var sectionIndexTrackingBackgroundColor: UIColor?Objective-C
@property(nonatomic, strong) UIColor *sectionIndexTrackingBackgroundColorDiscussion
Table views can display an index along the side of the view, making it easier for users to navigate the contents of the table quickly. This property specifies the color to display in the background of the index when the user drags a finger through it. A value of
nilrepresents the default color.Availability
Available in iOS 6.0 and later.
-
A Boolean value that indicates whether the table view should automatically return the focus to the cell at the last focused index path.
Declaration
Swift
var remembersLastFocusedIndexPath: BoolObjective-C
@property(nonatomic) BOOL remembersLastFocusedIndexPathDiscussion
When this property is set to
YEStrue, the table view remembers which index path was focused when focus leaves the table view, and automatically redirects focus back to that index path if focus moves back into the table view. By default, this property is set toNOfalse.Availability
Available in iOS 9.0 and later.
-
The style of the table view.
Declaration
Swift
enum UITableViewStyle : Int { case Plain case Grouped }Objective-C
typedef enum { UITableViewStylePlain, UITableViewStyleGrouped } UITableViewStyle;Constants
-
PlainUITableViewStylePlainA plain table view. Any section headers or footers are displayed as inline separators and float when the table view is scrolled.
Available in iOS 2.0 and later.
-
GroupedUITableViewStyleGroupedA table view whose sections present distinct groups of rows. The section headers and footers do not float.
Available in iOS 2.0 and later.
Discussion
You set the table style when you initialize the table view (see
initWithFrame:style:). You cannot modify the style thereafter.Import Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 2.0 and later.
-
-
The position in the table view (top, middle, bottom) to which a given row is scrolled.
Declaration
Swift
enum UITableViewScrollPosition : Int { case None case Top case Middle case Bottom }Objective-C
typedef enum { UITableViewScrollPositionNone, UITableViewScrollPositionTop, UITableViewScrollPositionMiddle, UITableViewScrollPositionBottom } UITableViewScrollPosition;Constants
-
NoneUITableViewScrollPositionNoneThe table view scrolls the row of interest to be fully visible with a minimum of movement. If the row is already fully visible, no scrolling occurs. For example, if the row is above the visible area, the behavior is identical to that specified by
UITableViewScrollPositionTop. This is the default.Available in iOS 2.0 and later.
-
TopUITableViewScrollPositionTopThe table view scrolls the row of interest to the top of the visible table view.
Available in iOS 2.0 and later.
-
MiddleUITableViewScrollPositionMiddleThe table view scrolls the row of interest to the middle of the visible table view.
Available in iOS 2.0 and later.
-
BottomUITableViewScrollPositionBottomThe table view scrolls the row of interest to the bottom of the visible table view.
Available in iOS 2.0 and later.
Discussion
You set the scroll position through a parameter of the
selectRowAtIndexPath:animated:scrollPosition:,scrollToNearestSelectedRowAtScrollPosition:animated:,cellForRowAtIndexPath:, andindexPathForSelectedRowmethods.Import Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 2.0 and later.
-
-
The type of animation when rows are inserted or deleted.
Declaration
Swift
enum UITableViewRowAnimation : Int { case Fade case Right case Left case Top case Bottom case None case Middle case Automatic }Objective-C
typedef enum { UITableViewRowAnimationFade, UITableViewRowAnimationRight, UITableViewRowAnimationLeft, UITableViewRowAnimationTop, UITableViewRowAnimationBottom, UITableViewRowAnimationNone, UITableViewRowAnimationMiddle, UITableViewRowAnimationAutomatic = 100 } UITableViewRowAnimation;Constants
-
FadeUITableViewRowAnimationFadeThe inserted or deleted row or rows fade into or out of the table view.
Available in iOS 2.0 and later.
-
RightUITableViewRowAnimationRightThe inserted row or rows slide in from the right; the deleted row or rows slide out to the right.
Available in iOS 2.0 and later.
-
LeftUITableViewRowAnimationLeftThe inserted row or rows slide in from the left; the deleted row or rows slide out to the left.
Available in iOS 2.0 and later.
-
TopUITableViewRowAnimationTopThe inserted row or rows slide in from the top; the deleted row or rows slide out toward the top.
Available in iOS 2.0 and later.
-
BottomUITableViewRowAnimationBottomThe inserted row or rows slide in from the bottom; the deleted row or rows slide out toward the bottom.
Available in iOS 2.0 and later.
-
NoneUITableViewRowAnimationNoneThe inserted or deleted rows use the default animations.
Available in iOS 3.0 and later.
-
MiddleUITableViewRowAnimationMiddleThe table view attempts to keep the old and new cells centered in the space they did or will occupy. Available in iPhone 3.2.
Available in iOS 3.2 and later.
-
AutomaticUITableViewRowAnimationAutomaticThe table view chooses an appropriate animation style for you. (Introduced in iOS 5.0.)
Available in iOS 5.0 and later.
Discussion
You specify one of these constants as a parameter of the
insertRowsAtIndexPaths:withRowAnimation:,insertSections:withRowAnimation:,deleteRowsAtIndexPaths:withRowAnimation:,deleteSections:withRowAnimation:,reloadRowsAtIndexPaths:withRowAnimation:, andreloadSections:withRowAnimation:methods.Import Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 2.0 and later.
-
-
Requests icon to be shown in the section index of a table view.
Declaration
Swift
let UITableViewIndexSearch: StringObjective-C
UIKIT_EXTERN NSString *const UITableViewIndexSearch;Constants
-
UITableViewIndexSearchUITableViewIndexSearchIf the data source includes this constant string in the array of strings it returns in
sectionIndexTitlesForTableView:, the section index displays a magnifying glass icon at the corresponding index location. This location should generally be the first title in the index.Available in iOS 3.0 and later.
-
-
The default value for a given dimension.
Declaration
Swift
let UITableViewAutomaticDimension: CGFloatObjective-C
UIKIT_EXTERN const CGFloat UITableViewAutomaticDimension;Constants
-
UITableViewAutomaticDimensionUITableViewAutomaticDimensionRequests that
UITableViewuse the default value for a given dimension.Available in iOS 5.0 and later.
Discussion
You return this value from
UITableViewDelegatemethods that request dimension metrics when you wantUITableViewto choose a default value. For example, if you return this constant intableView:heightForHeaderInSection:ortableView:heightForFooterInSection:,UITableViewuses a height that fits the value returned fromtableView:titleForHeaderInSection:ortableView:titleForFooterInSection:(if the title is notnil). -
-
Posted when the selected row in the posting table view changes.
There is no
userInfodictionary associated with this notification.Declaration
Swift
let UITableViewSelectionDidChangeNotification: StringImport Statement
Objective-C
@import UIKit;Swift
import UIKitAvailability
Available in iOS 2.0 and later.
Copyright © 2016 Apple Inc. All rights reserved. Terms of Use | Privacy Policy | Updated: 2015-12-10
