Skip to content

Commit

Permalink
Fix (again) willBeginEditingRowAt/didEndEditingRowAt changes
Browse files Browse the repository at this point in the history
TLDR: Changed the willBeginEditingRowAt/didEndEditingRowAt delegate methods by adding an orientation parameter to differentiate them from the equivalent UITableView methods.

This change addresses the issue introduced when adding willBeginEditingRowAt/didEndEditingRowAt delegate methods to SwipeTableViewCellDelegate.  Since these method names matched the existing UITableViewDelegate, it causes the UITableView to enter standard editing mode.  The UITableViewController implementation of the delegate methods call setEditing on the UIViewController (itself) which feeds back into UITableView.  UITableView uses private flags to differentiate the difference between "editingForSwipe" and regular "editing".  But since SwipeCellKit initiated the swipe, it doesn't know its already in "editingForSwipe" mode and assumes standard editing mode, which obviously conflicts with the actual swipe.
  • Loading branch information
jerkoch committed Mar 18, 2017
1 parent 841163a commit 95889a1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
7 changes: 0 additions & 7 deletions Example/MailExample/MailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,6 @@ extension MailViewController: SwipeTableViewCellDelegate {
return options
}

override func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath) {
}


override func tableView(_ tableView: UITableView, didEndEditingRowAt indexPath: IndexPath?) {
}

func configure(action: SwipeAction, with descriptor: ActionDescriptor) {
action.title = descriptor.title(forDisplayMode: buttonDisplayMode)
action.image = descriptor.image(forStyle: buttonStyle, displayMode: buttonDisplayMode)
Expand Down
9 changes: 5 additions & 4 deletions Source/SwipeTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,14 @@ open class SwipeTableViewCell: UITableViewCell {
}

func notifyEditingStateChange(active: Bool) {
guard let tableView = tableView,
guard let actionsView = actionsView,
let tableView = tableView,
let indexPath = tableView.indexPath(for: self) else { return }

if active {
delegate?.tableView(tableView, willBeginEditingRowAt: indexPath)
delegate?.tableView(tableView, willBeginEditingRowAt: indexPath, for: actionsView.orientation)
} else {
delegate?.tableView(tableView, didEndEditingRowAt: indexPath)
delegate?.tableView(tableView, didEndEditingRowAt: indexPath, for: actionsView.orientation)
}
}

Expand Down Expand Up @@ -503,7 +504,7 @@ extension SwipeTableViewCell: SwipeActionsViewDelegate {
action.handler?(action, indexPath)
tableView.deleteRows(at: [indexPath], with: .none)

delegate?.tableView(tableView, didEndEditingRowAt: indexPath)
delegate?.tableView(tableView, didEndEditingRowAt: indexPath, for: actionsView.orientation)

UIView.animate(withDuration: 0.3, animations: {
mask.frame.size.height = 0
Expand Down
16 changes: 10 additions & 6 deletions Source/SwipeTableViewCellDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,24 @@ public protocol SwipeTableViewCellDelegate: class {
/**
Tells the delegate that the table view is about to go into editing mode.
- parameter tableView: The table view object which owns the cell requesting this information.
- parameter tableView: The table view object providing this information.
- parameter indexPath: The index path of the row.
- parameter orientation: The side of the cell.
*/
func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath)
func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation)

/**
Tells the delegate that the table view has left editing mode.
- parameter tableView: The table view object which owns the cell requesting this information.
- parameter tableView: The table view object providing this information.
- parameter indexPath: The index path of the row.
- parameter orientation: The side of the cell.
*/
func tableView(_ tableView: UITableView, didEndEditingRowAt indexPath: IndexPath?)
func tableView(_ tableView: UITableView, didEndEditingRowAt indexPath: IndexPath?, for orientation: SwipeActionsOrientation)
}

/**
Expand All @@ -66,7 +70,7 @@ public extension SwipeTableViewCellDelegate {
return SwipeTableOptions()
}

func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath) {}
func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) {}

func tableView(_ tableView: UITableView, didEndEditingRowAt indexPath: IndexPath?) {}
func tableView(_ tableView: UITableView, didEndEditingRowAt indexPath: IndexPath?, for orientation: SwipeActionsOrientation) {}
}

0 comments on commit 95889a1

Please sign in to comment.