【ios学习】UITableViewDelegate

UITableViewDelegate

Methods for managing selections, configuring section headers and footers, deleting and reordering cells, and performing other actions in a table view.

On This Page

Declaration

protocol UITableViewDelegate

Overview

Use the methods of this protocol to manage the following features:

  • Create and manage custom header and footer views.

  • Specify custom heights for rows, headers, and footers.

  • Provide height estimates for better scrolling support.

  • Indent row content.

  • Respond to row selections.

  • Respond to swipes and other actions in table rows.

  • Support editing the table's content.

The table view specifies rows and sections using NSIndexPath objects. For information about how to interpret row and section indexes, see Specifying the Location of Rows and Sections.

Topics

Configuring Rows for the Table View

func tableView(UITableView, willDisplay: UITableViewCell, forRowAt: IndexPath)

Tells the delegate the table view is about to draw a cell for a particular row.

func tableView(UITableView, indentationLevelForRowAt: IndexPath) -> Int

Asks the delegate to return the level of indentation(缩进) for a row in a given section.

func tableView(UITableView, shouldSpringLoadRowAt: IndexPath, with: UISpringLoadedInteractionContext) -> Bool

Called to let you fine tune the spring-loading behavior of the rows in a table.

Responding to Row Selections

func tableView(UITableView, willSelectRowAt: IndexPath) -> IndexPath?

Tells the delegate that a specified row is about to be selected.

func tableView(UITableView, didSelectRowAt: IndexPath)

Tells the delegate that the specified row is now selected.

func tableView(UITableView, willDeselectRowAt: IndexPath) -> IndexPath?

Tells the delegate that a specified row is about to be deselected.

func tableView(UITableView, didDeselectRowAt: IndexPath)

Tells the delegate that the specified row is now deselected.

Providing Custom Header and Footer Views

func tableView(UITableView, viewForHeaderInSection: Int) -> UIView?

Asks the delegate for a view object to display in the header of the specified section of the table view.

func tableView(UITableView, viewForFooterInSection: Int) -> UIView?

Asks the delegate for a view object to display in the footer of the specified section of the table view.

func tableView(UITableView, willDisplayHeaderView: UIView, forSection: Int)

Tells the delegate that the table is about to display the header view for the specified section.

func tableView(UITableView, willDisplayFooterView: UIView, forSection: Int)

Tells the delegate that the table is about to display the footer view for the specified section.

Providing Header, Footer, and Row Heights

func tableView(UITableView, heightForRowAt: IndexPath) -> CGFloat

Asks the delegate for the height to use for a row in a specified location.

func tableView(UITableView, heightForHeaderInSection: Int) -> CGFloat

Asks the delegate for the height to use for the header of a particular section.

func tableView(UITableView, heightForFooterInSection: Int) -> CGFloat

Asks the delegate for the height to use for the footer of a particular section.

class let automaticDimension: CGFloat

A constant representing the default value for a given dimension.

Estimating Heights for the Table's Content

func tableView(UITableView, estimatedHeightForRowAt: IndexPath) -> CGFloat

Asks the delegate for the estimated height of a row in a specified location.

func tableView(UITableView, estimatedHeightForHeaderInSection: Int) -> CGFloat

Asks the delegate for the estimated height of the header of a particular section.

func tableView(UITableView, estimatedHeightForFooterInSection: Int) -> CGFloat

Asks the delegate for the estimated height of the footer of a particular section.

Managing Accessory Views

func tableView(UITableView, accessoryButtonTappedForRowWith: IndexPath)

Tells the delegate that the user tapped the detail button for the specified row.

Responding to Row Actions

func tableView(UITableView, leadingSwipeActionsConfigurationForRowAt: IndexPath) -> UISwipeActionsConfiguration?

Returns the swipe actions to display on the leading edge of the row.

func tableView(UITableView, trailingSwipeActionsConfigurationForRowAt: IndexPath) -> UISwipeActionsConfiguration?

Returns the swipe actions to display on the trailing edge of the row.

func tableView(UITableView, shouldShowMenuForRowAt: IndexPath) -> Bool

Asks the delegate if the editing menu should be shown for a certain row.

func tableView(UITableView, canPerformAction: Selector, forRowAt: IndexPath, withSender: Any?) -> Bool

Asks the delegate if the editing menu should omit the Copy or Paste command for a given row.

func tableView(UITableView, performAction: Selector, forRowAt: IndexPath, withSender: Any?)

Tells the delegate to perform a copy or paste operation on the content of a given row.

func tableView(UITableView, editActionsForRowAt: IndexPath) -> [UITableViewRowAction]?

Asks the delegate for the actions to display in response to a swipe in the specified row.

Managing Table View Highlights

func tableView(UITableView, shouldHighlightRowAt: IndexPath) -> Bool

Asks the delegate if the specified row should be highlighted.

func tableView(UITableView, didHighlightRowAt: IndexPath)

Tells the delegate that the specified row was highlighted.

func tableView(UITableView, didUnhighlightRowAt: IndexPath)

Tells the delegate that the highlight was removed from the row at the specified index path.

Editing Table Rows

func tableView(UITableView, willBeginEditingRowAt: IndexPath)

Tells the delegate that the table view is about to go into editing mode.

func tableView(UITableView, didEndEditingRowAt: IndexPath?)

Tells the delegate that the table view has left editing mode.

func tableView(UITableView, editingStyleForRowAt: IndexPath) -> UITableViewCell.EditingStyle

Asks the delegate for the editing style of a row at a particular location in a table view.

func tableView(UITableView, titleForDeleteConfirmationButtonForRowAt: IndexPath) -> String?

Changes the default title of the delete-confirmation button.

func tableView(UITableView, shouldIndentWhileEditingRowAt: IndexPath) -> Bool

Asks the delegate whether the background of the specified row should be indented while the table view is in editing mode.

Reordering Table Rows

func tableView(UITableView, targetIndexPathForMoveFromRowAt: IndexPath, toProposedIndexPath: IndexPath) -> IndexPath

Asks the delegate to return a new index path to retarget a proposed move of a row.

Tracking the Removal of Views

func tableView(UITableView, didEndDisplaying: UITableViewCell, forRowAt: IndexPath)

Tells the delegate that the specified cell was removed from the table.

func tableView(UITableView, didEndDisplayingHeaderView: UIView, forSection: Int)

Tells the delegate that the specified header view was removed from the table.

func tableView(UITableView, didEndDisplayingFooterView: UIView, forSection: Int)

Tells the delegate that the specified footer view was removed from the table.

Managing Table View Focus

func tableView(UITableView, canFocusRowAt: IndexPath) -> Bool

Asks the delegate whether the cell at the specified index path is itself focusable.

func tableView(UITableView, shouldUpdateFocusIn: UITableViewFocusUpdateContext) -> Bool

Asks the delegate whether the focus update specified by the context is allowed to occur.

func tableView(UITableView, didUpdateFocusIn: UITableViewFocusUpdateContext, with: UIFocusAnimationCoordinator)

Tells the delegate that a focus update specified by the context has just occurred.

func indexPathForPreferredFocusedView(in: UITableView) -> IndexPath?

Asks the delegate for the table view’s index path for the preferred focused view.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值