@@ -71,6 +71,8 @@ public class UIKeyCommandTableView: UITableView {
7171
7272 public var activateSelectionKeyCommandOptions : [ UIKeyCommand . Options ] = [ . spaceBar, . return]
7373
74+ public var activateAccessoryButtonKeyCommandOptions : [ UIKeyCommand . Options ] = [ ]
75+
7476 public var clearSelectionKeyCommandOptions : [ UIKeyCommand . Options ] = [ ]
7577
7678 public override var keyCommands : [ UIKeyCommand ] ? {
@@ -88,6 +90,10 @@ public class UIKeyCommandTableView: UITableView {
8890 keyCommands. append ( UIKeyCommand ( $0, action: #selector( activateSelection) ) )
8991 }
9092
93+ activateAccessoryButtonKeyCommandOptions. forEach {
94+ keyCommands. append ( UIKeyCommand ( $0, action: #selector( activateAccessorySelection) ) )
95+ }
96+
9197 clearSelectionKeyCommandOptions. forEach {
9298 keyCommands. append ( UIKeyCommand ( $0, action: #selector( clearSelection) ) )
9399 }
@@ -252,24 +258,19 @@ private extension UIKeyCommandTableView {
252258 }
253259
254260 func activateSelection( ) {
255- var selectableIndexPath : IndexPath ? {
256- guard let indexPathForSelectedRow = indexPathForSelectedRow else {
257- return nil
258- }
259-
260- guard
261- let delegate = delegate,
262- delegate. responds ( to: #selector( UITableViewDelegate . tableView ( _: willSelectRowAt: ) ) )
263- else {
264- return indexPathForSelectedRow
265- }
266-
267- return delegate. tableView ? ( self , willSelectRowAt: indexPathForSelectedRow)
261+ guard let selectedIndexPath = selectableIndexPath else {
262+ return
268263 }
269264
270- if let selectedIndexPath = selectableIndexPath {
271- delegate? . tableView ? ( self , didSelectRowAt: selectedIndexPath)
265+ delegate? . tableView ? ( self , didSelectRowAt: selectedIndexPath)
266+ }
267+
268+ func activateAccessorySelection( ) {
269+ guard let selectedIndexPath = selectableIndexPath else {
270+ return
272271 }
272+
273+ delegate? . tableView ? ( self , accessoryButtonTappedForRowWith: selectedIndexPath)
273274 }
274275
275276 func selectPrevious( ) {
@@ -287,6 +288,21 @@ private extension UIKeyCommandTableView {
287288
288289 selectRowIfPossible ( at: currentSelection. nextRow ( ) )
289290 }
291+
292+ var selectableIndexPath : IndexPath ? {
293+ guard let indexPathForSelectedRow = indexPathForSelectedRow else {
294+ return nil
295+ }
296+
297+ guard
298+ let delegate = delegate,
299+ delegate. responds ( to: #selector( UITableViewDelegate . tableView ( _: willSelectRowAt: ) ) )
300+ else {
301+ return indexPathForSelectedRow
302+ }
303+
304+ return delegate. tableView ? ( self , willSelectRowAt: indexPathForSelectedRow)
305+ }
290306}
291307
292308// MARK: - Row Visibility
0 commit comments