• 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: Very odd issue when try to implement the drag and drop functions for NSOutlineview
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Very odd issue when try to implement the drag and drop functions for NSOutlineview


  • Subject: Re: Very odd issue when try to implement the drag and drop functions for NSOutlineview
  • From: chaitanya pandit <email@hidden>
  • Date: Wed, 10 Dec 2008 21:16:03 +0530

Hi,
This was a reply that i posted recently for a similar question, i think you are missing step 2


To re-order the items in the tableView, you will have to implement a custom drag type.
Say for example you name your custom drag type as @"myDragType"
then
1] Register your table view to accept this drag type using "registerForDraggedTypes:" and passing an array containing @"myDragType" along with super's drag types
2] In your tableView's data source, implement this method "tableView:namesOfPromisedFilesDroppedAtDestination:forDraggedRowsWithIndexes :" and return an array containing @"myDragType".
3] Implement "tableView:writeRowsWithIndexes:toPasteboard:" in your data source and write any dummy data in the given pasteboard for type @"myDragType", this can be the data representing the items/indexes being dragged
4] Check for a valid drop with "tableView:validateDrop:proposedRow:proposedDropOperation:"
5] Finally set the new indexes for the dragged items in "tableView:acceptDrop:row:dropOperation:"
HTH,
Chaitanya


On 10-Dec-08, at 9:07 PM, Alex.Wang wrote:

Hi, everyone.
Currently I am working on a project which uses the NSOutlineview heavily. I
thought the drag and drop functions are very important, so I am trying to
implement that.
However, after refer to some tutorials, I still can't make it work... My
steps are :
1. create a controller to manage the outlineview, set the controller to the
datasouce and delegate for the outlineview.
2. register the outineview with the following code in the awakeFromNib
method:
[_outlineView registerForDraggedTypes:
[NSArray arrayWithObject:MyPrivateTableViewDataType]];
3. implement the following methods:
- (BOOL)outlineView:(NSOutlineView *)ov
writeItems:(NSArray *)items
toPasteboard:(NSPasteboard *)pboard
{


    draggedNodes = items;
   NSlog(@"In the outlinew writeItems method!");
    [pboard declareTypes:[NSArray
arrayWithObject:MyPrivateTableViewDataType] owner:self];
    [pboard setData:[NSData data] forType:MyPrivateTableViewDataType];

   return YES;
}

- (NSDragOperation)outlineView:(NSOutlineView*)ov
                 validateDrop:(id <NSDraggingInfo>)info
                 proposedItem:(id)item
           proposedChildIndex:(NSInteger)childIndex{

     NSLog(@"Return the NSDragOperation");
   draggedNodes = [[[info draggingSource] dataSource] draggedNodes];
       return NSDragOperationGeneric;
}

- (BOOL)outlineView:(NSOutlineView *)ov
        acceptDrop:(id <NSDraggingInfo>)info
              item:(id)item
        childIndex:(NSInteger)childIndex
{
  NSLog(@"should we return the accetpDrop?");
  return YES;
}

After compiled the application and set it up, I had no chance to
successfully get anything from the console although there are so many output
statements when I drag and drop items repeatly.
Can anyone here give me some help or guidance about this issue?
Thank you very much for any help. Good luck.


--
Best regards.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Very odd issue when try to implement the drag and drop functions for NSOutlineview (From: Alex.Wang <email@hidden>)

  • Prev by Date: how to pass arguments by reference
  • Next by Date: Re: how to pass arguments by reference
  • Previous by thread: Very odd issue when try to implement the drag and drop functions for NSOutlineview
  • Next by thread: how to pass arguments by reference
  • Index(es):
    • Date
    • Thread