Instance Method

performBatchUpdates(_:completion:)

Animates multiple insert, delete, reload, and move operations as a group.

Declaration

func performBatchUpdates(_ updates: (() -> Void)?, completion: ((Bool) -> Void)? = nil)

Parameters

updates

The block that performs the relevant insert, delete, reload, or move operations.

completion

A completion handler block to execute when all of the operations are finished. This block has no return value and takes the following parameter:

finished

A Boolean value indicating whether the animations completed successfully. The value of this parameter is false if the animations were interrupted for any reason.

Discussion

Use this method in cases where you want to make multiple changes to the table view in one single animated operation, as opposed to several separate animations. Use the block passed in the updates parameter to specify all of the operations you want to perform.

Deletes are processed before inserts in batch operations. This means the indexes for the deletions are processed relative to the indexes of the table view’s state before the batch operation, and the indexes for the insertions are processed relative to the indexes of the state after all the deletions in the batch operation.

See Also

Inserting, Deleting, and Moving Rows and Sections

func insertRows(at: [IndexPath], with: UITableView.RowAnimation)

Inserts rows in the table view at the locations identified by an array of index paths, with an option to animate the insertion.

func deleteRows(at: [IndexPath], with: UITableView.RowAnimation)

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

func moveRow(at: IndexPath, to: IndexPath)

Moves the row at a specified location to a destination location.

func insertSections(IndexSet, with: UITableView.RowAnimation)

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

func deleteSections(IndexSet, with: UITableView.RowAnimation)

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

func moveSection(Int, toSection: Int)

Moves a section to a new location in the table view.

func beginUpdates()

Begins a series of method calls that insert, delete, or select rows and sections of the table view.

func endUpdates()

Concludes a series of method calls that insert, delete, select, or reload rows and sections of the table view.