2 Replies
      Latest reply on Aug 2, 2016 9:37 AM by MarcMV
      MarcMV Level 1 Level 1 (0 points)

        Hello,

         

        I would like to add copy (Command + C) functionality to my NSTableView for a row (or multiple rows) that the user has selected.

         

        I've tried adding in the NSTableViewController the following things with no luck, the copy function (Command + C) always appears greyed out in the menu:

         

        1.

            override func copy() -> AnyObject {

                print("TEST: copytriggered") /*Here i would copy to clipboard the selected rows*/

                return true

            }

         

        2.

        Conforming to NSCopying, implementing copyWithZone...

         

        3.

        Trying 1 and 2 in the window controller and app delegate.

         

        4.

        Adding func tableView(_ tableView: NSTableView, pasteboardWriterForRow row: Int) -> NSPasteboardWriting? in the TableView data source.

         

        I have no clue what to do at this point, any help appreciated.

         

        Thanks,

         

        Marc

        • Re: Copy NSTableView row greyed out
          Ken Thomases Level 4 Level 4 (645 points)

          You are confusing the Copy edit action method with the methods for making a duplicate of an object.  The NSCopying protocol and the copyWithZone() method are for the latter, enabling an object to create a copy of itself.  Likewise, the copy() method is just a convenience cover method for copyWithZone().

           

          The action method for the Copy edit menu item is subtly different.  It's "func copy(_ sender: AnyObject?)".  That's the general form for all action methods, taking a sender argument and not returning anything.  You need to implement that method.

           

          Finally, tableView(_:pasteboardWriterForRow:) is generally only used for drag-and-drop, when the user drags a row.