How to implement a swipeable NSTableVIew cell?

I want to implemtn a swipeable cell view like in iOS for an OSX app. I haven't found any discussion or tutorial for this requirement, but I have seen already mac applications with sipeable content.

Replies

The swipe-to-the-side-to-reveal-extra-actions feature was added to OS X in version 10.11. Check out NSTableView.h and look at the following API in the NSTableViewDelegate protocol:


/* Optional - Row actions for a "swipe to delete" feature to show a button on the left or right of a row to do some action (typically deletion).


View Based TableView: Return an array of NSTableViewRowAction objects to be shown on the ‘edge’, where the NSTableRowActionEdge is either the leading or trailing edge of an NSTableRowView. The edge is determined automatically by the table based on the swipe direction. Return an empty array to not show any actions on a given edge.

*/

- (NSArray<NSTableViewRowAction *> *)tableView:(NSTableView *)tableView rowActionsForRow:(NSInteger)row edge:(NSTableRowActionEdge)edge NS_AVAILABLE_MAC(10_11);


Also look at NSTableViewRowAction.h for the core of the feature. There's a bit of customization ability, but it's limited to title, color, and one of two animation styles (regular, which pops across, or destructive, which flattens).


Edit: what I wrote about the animation styles is incomplete. The fundamental difference between regular and destructive behaviors is the ease with which they are triggered by swiping farther across the row. To activate a regular action, you have to pull just a bit farther; to activate a destructive action, you have to pull almost all the way across the row, lessening the chance of accidentally deleting something. If for a destructive action you update your model, causing a row to be removed with an animation like Fade or SlideRight, the row action will do the "flatten" animation shown by Mail.

Do you know any way of collapsing the "action menu" ? we have some non-removing actions yet we can't seem to be able to collapse the action menu after a user has selected an action (we have pause/resume etc which should collapse the menu)

The actions should disappear as soon as one is selected. Or are you referring to the "flatten" animation done by Mail? I think that was a custom implementation using a standard row removal animation (-removeRowsAtIndexes:withAnimation:)


Edit: see below

  • How to set the swap adjust limit, like when swap i have to set the limit if the limit exceed i have to perform action? how can i do

Add a Comment

How odd. They don't seem to disappear here. Let me investigate further. Thanks for telling me it should disappear.

My earlier post was in error. Row actions do not necessarily hide once one is selected. In your row action's handler, set the rowActionsVisible property to NO or false to have the actions collapse. Don't worry about re-enabling them—that will happen automatically when you do it like this.

Awesome, weird API - was looking to disable the actions menu and skipped the write-only property as it seemed illogical.

Thanks for helping me Bob.

Yeah, I don't know if that's the "correct" way to do it, but it sure seems to work well!

you are a life saver, I spent hors to figure out how to dismiss the action :S

How to set the swap adjust limit, like when swap i have to set the limit if the limit exceed i have to perform action? how can i do