SwipeTableViewCellDelegate.swift 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // SwipeTableViewCellDelegate.swift
  3. //
  4. // Created by Jeremy Koch
  5. // Copyright © 2017 Jeremy Koch. All rights reserved.
  6. //
  7. import UIKit
  8. /**
  9. The `SwipeTableViewCellDelegate` protocol is adopted by an object that manages the display of action buttons when the cell is swiped.
  10. */
  11. public protocol SwipeTableViewCellDelegate: class {
  12. /**
  13. Asks the delegate for the actions to display in response to a swipe in the specified row.
  14. - parameter tableView: The table view object which owns the cell requesting this information.
  15. - parameter indexPath: The index path of the row.
  16. - parameter orientation: The side of the cell requesting this information.
  17. - returns: An array of `SwipeAction` objects representing the actions for the row. Each action you provide is used to create a button that the user can tap. Returning `nil` will prevent swiping for the supplied orientation.
  18. */
  19. func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]?
  20. /**
  21. Asks the delegate for the display options to be used while presenting the action buttons.
  22. - parameter tableView: The table view object which owns the cell requesting this information.
  23. - parameter indexPath: The index path of the row.
  24. - parameter orientation: The side of the cell requesting this information.
  25. - returns: A `SwipeOptions` instance which configures the behavior of the action buttons.
  26. - note: If not implemented, a default `SwipeOptions` instance is used.
  27. */
  28. func tableView(_ tableView: UITableView, editActionsOptionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> SwipeOptions
  29. /**
  30. Tells the delegate that the table view is about to go into editing mode.
  31. - parameter tableView: The table view object providing this information.
  32. - parameter indexPath: The index path of the row.
  33. - parameter orientation: The side of the cell.
  34. */
  35. func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation)
  36. /**
  37. Tells the delegate that the table view has left editing mode.
  38. - parameter tableView: The table view object providing this information.
  39. - parameter indexPath: The index path of the row.
  40. - parameter orientation: The side of the cell.
  41. */
  42. func tableView(_ tableView: UITableView, didEndEditingRowAt indexPath: IndexPath?, for orientation: SwipeActionsOrientation)
  43. /**
  44. Asks the delegate for visibile rectangle of the table view, which is used to ensure swipe actions are vertically centered within the visible portion of the cell.
  45. - parameter tableView: The table view object providing this information.
  46. - returns: The visible rectangle of the table view.
  47. - note: The returned rectange should be in the table view's own coordinate system. Returning `nil` will result in no vertical offset to be be calculated.
  48. */
  49. func visibleRect(for tableView: UITableView) -> CGRect?
  50. }
  51. /**
  52. Default implementation of `SwipeTableViewCellDelegate` methods
  53. */
  54. public extension SwipeTableViewCellDelegate {
  55. func tableView(_ tableView: UITableView, editActionsOptionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> SwipeOptions {
  56. return SwipeOptions()
  57. }
  58. func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) {}
  59. func tableView(_ tableView: UITableView, didEndEditingRowAt indexPath: IndexPath?, for orientation: SwipeActionsOrientation) {}
  60. func visibleRect(for tableView: UITableView) -> CGRect? {
  61. return nil
  62. }
  63. }