• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Copy and Paste of rows in a NSTableView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Copy and Paste of rows in a NSTableView


  • Subject: Re: Copy and Paste of rows in a NSTableView
  • From: Luke Adamson <email@hidden>
  • Date: Mon, 11 Jun 2001 23:46:33 -0700

On Monday, June 11, 2001, at 06:55 AM, Stiphane Sudre wrote:

I have a NSTableView and want to be able to copy/paste data relating the lines selected.

You do this by implementing copy:/paste: in your controller and then using the result of [[self window] firstResponder] (or similar) to determine which view to copy from/paste into (assuming the firstResponder doesn't implement copy:/paste: directly, as NSTextView does).

Rough pseudocode:

- (void)copy:(id)sender;
{
NSResponder *firstResponder;

firstResponder = [[self window] firstResponder];
if (firstResponder == myTableViewOfSongs) {
[songs addObjectsFromArray:[MySongClass songsFromPasteboard:[NSPasteboard generalPasteboard]];
[songsTableView reloadData];
} else if (firstResponder == myTableViewOfArtists) {
[artists addObjectsFromArray:[MySongClass songsFromPasteboard:[NSPasteboard generalPasteboard]];
[artistsTableView reloadData];
} else {
// Validation should probably prevent this case, but if it happens...
NSBeep();
}
}

I've finally found a solution using the First Responder but is there not a solution using the delegate of the NSTableView ?

Using the firstResponder is the "correct" mechanism for doing this. The object which will respond to the copy:/paste: method will very likely be the delegate (and data source) of the NSTableView (unless you're working with a contrived, or complex case). But, it will be in the responder chain because it will also be the delegate of the window which "contains" the table view (the main window's delegate is in the responder chain by definition).

Have fun!
---
Luke
_______________________________________________
MacOSX-dev mailing list
email@hidden
http://www.omnigroup.com/mailman/listinfo/macosx-dev


  • Prev by Date: Re: Start & Stop demon
  • Next by Date: Re: Handling Dragged Urls
  • Previous by thread: Re: Copy and Paste of rows in a NSTableView
  • Next by thread: Re: Copy and Paste of rows in a NSTableView
  • Index(es):
    • Date
    • Thread