Skip to content

Commit

Permalink
Merge pull request #134 from alanzeino/indexpath
Browse files Browse the repository at this point in the history
Pass the IndexPath to an EditAction's selection
  • Loading branch information
eliperkins authored Nov 20, 2018
2 parents b765be7 + 68ac39d commit f8867ec
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ class ViewController: TableViewController {
]),
Section(header: "Editing", rows: [
Row(text: "Swipe this row", editActions: [
Row.EditAction(title: "Warn", backgroundColor: .orange, selection: { [unowned self] in
self.showAlert(title: "Warned.")
Row.EditAction(title: "Warn", backgroundColor: .orange, selection: { [unowned self] (indexPath) in
self.showAlert(title: "Warned at indexPath: \(indexPath).")
}),
Row.EditAction(title: "Delete", style: .destructive, selection: { [unowned self] in
self.showAlert(title: "Deleted.")
Row.EditAction(title: "Delete", style: .destructive, selection: { [unowned self] (indexPath) in
self.showAlert(title: "Deleted at indexPath: \(indexPath).")
})
])
]),
Expand Down
2 changes: 1 addition & 1 deletion Static/DataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ extension DataSource: UITableViewDataSource {
return row(at: indexPath)?.editActions.map {
action in
let rowAction = UITableViewRowAction(style: action.style, title: action.title) { (_, _) in
action.selection?()
action.selection?(indexPath)
}

// These calls have side effects when setting to nil
Expand Down
5 changes: 3 additions & 2 deletions Static/Row.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public struct Row: Hashable, Equatable {
}

public typealias Context = [String: Any]
public typealias EditActionSelection = (IndexPath) -> ()

/// Representation of an editing action, when swiping to edit a cell.
public struct EditAction {
Expand All @@ -86,9 +87,9 @@ public struct Row: Hashable, Equatable {
public let backgroundEffect: UIVisualEffect?

/// Invoked when selecting the action.
public let selection: Selection?
public let selection: EditActionSelection?

public init(title: String, style: UITableViewRowAction.Style = .default, backgroundColor: UIColor? = nil, backgroundEffect: UIVisualEffect? = nil, selection: Selection? = nil) {
public init(title: String, style: UITableViewRowAction.Style = .default, backgroundColor: UIColor? = nil, backgroundEffect: UIVisualEffect? = nil, selection: EditActionSelection? = nil) {
self.title = title
self.style = style
self.backgroundColor = backgroundColor
Expand Down

0 comments on commit f8867ec

Please sign in to comment.