UITableView

extension UITableView
  • Registers a UITableViewCell for use in a UITableView.

    By default, the class name of the cell is used as the reuse identifier.

    Example:

    class CustomCell: UITableViewCell {}
    
    let tableView = UITableView()
    
    // registers the CustomCell class with a reuse identifier of "CustomCell"
    tableView.registerCell(CustomCell)
    

    Declaration

    Swift

    public func registerCell<T>(_ type: T.Type, withIdentifier reuseIdentifier: String = String(describing: T.self)) where T : UITableViewCell

    Parameters

    type

    The type of cell to register.

    reuseIdentifier

    The reuse identifier for the cell (optional).

  • Dequeues a UITableViewCell for use in a UITableView.

    By default, the class name of the cell is used as the reuse identifier.

    Example:

    class CustomCell: UITableViewCell {}
    
    let tableView = UITableView()
    
    // dequeues a CustomCell class
    let cell = tableView.dequeueReusableCell(CustomCell)
    

    Declaration

    Swift

    public func dequeueCell<T>(_ type: T.Type = T.self, withIdentifier reuseIdentifier: String = String(describing: T.self)) -> T where T : UITableViewCell

    Parameters

    type

    The type of the cell.

    reuseIdentifier

    The reuse identifier for the cell (optional).

    Return Value

    A force-casted UITableViewCell of the specified type.

  • Dequeues a UITableViewCell for use in a UITableView.

    By default, the class name of the cell is used as the reuse identifier.

    Example:

    class CustomCell: UITableViewCell {}
    
    let tableView = UITableView()
    
    // dequeues a CustomCell class
    let cell = tableView.dequeueReusableCell(CustomCell.self, forIndexPath: indexPath)
    

    Declaration

    Swift

    public func dequeueCell<T>(_ type: T.Type = T.self, withIdentifier reuseIdentifier: String = String(describing: T.self), for indexPath: IndexPath) -> T where T : UITableViewCell

    Parameters

    type

    The type of the cell.

    indexPath

    The index path at which to dequeue a new cell.

    reuseIdentifier

    The reuse identifier for the cell (optional).

    Return Value

    A force-casted UITableViewCell of the specified type.

  • Inserts rows into self.

    Declaration

    Swift

    public func insert(_ indices: [Int], section: Int = 0, animation: UITableView.RowAnimation = .automatic)

    Parameters

    indices

    The rows indices to insert into self.

    section

    The section in which to insert the rows (optional, defaults to 0).

    animation

    The animation to use for the row insertion (optional, defaults to .Automatic).

  • Deletes rows from self.

    Declaration

    Swift

    public func delete(_ indices: [Int], section: Int = 0, animation: UITableView.RowAnimation = .automatic)

    Parameters

    indices

    The rows indices to delete from self.

    section

    The section in which to delete the rows (optional, defaults to 0).

    animation

    The animation to use for the row deletion (optional, defaults to .Automatic).

  • Reloads rows in self.

    Declaration

    Swift

    public func reload(_ indices: [Int], section: Int = 0, animation: UITableView.RowAnimation = .automatic)

    Parameters

    indices

    The rows indices to reload in self.

    section

    The section in which to reload the rows (optional, defaults to 0).

    animation

    The animation to use for reloading the rows (optional, defaults to .Automatic).

  • The minimum (starting) IndexPath for traversing a UITableView sequentially.

    Declaration

    Swift

    public var minimumIndexPath: IndexPath { get }
  • The maximum (ending) IndexPath for traversing a UITableView sequentially.

    Declaration

    Swift

    public var maximumIndexPath: IndexPath { get }
  • When sequentially traversing a UITableView, what’s the next IndexPath after the given IndexPath.

    See also

    var maximumIndexpath

    Declaration

    Swift

    public func indexPath(after indexPath: IndexPath) -> IndexPath?

    Parameters

    indexPath

    The current indexPath; the path we want to find what comes after.

    Return Value

    The next indexPath, or nil if we’re at the maximumIndexPath

  • When sequentially traversing a UITableView, what’s the previous IndexPath before the given IndexPath.

    See also

    var minimumIndexPath

    Declaration

    Swift

    public func indexPath(before indexPath: IndexPath) -> IndexPath?

    Parameters

    indexPath

    The current indexPath; the path we want to find what comes before.

    Return Value

    The prior indexPath, or nil if we’re at the minimumIndexPath