views:

267

answers:

2

How would you make a Outline view able to be re-ordered (dragging to move the position of a row) like a Table View. At the moment when I try and Drag a row it just selects other rows. How can I make It re-orderable?

+6  A: 

You must implement the drag'n drop stuff.

These are the methods you have to implement in your NSOutlineView datasource.

- (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index;
- (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index;

Check NSOutlineViewDataSource Protocol Reference for detailed info.

You also need to register drag types for your outlineView

[outlineView registerForDraggedTypes: [NSArray arrayWithObjects: NSStringPboardType, NSURLPboardType, NSFilenamesPboardType,NSFileContentsPboardType, nil]];
cocoafan
Where is the NSOutlineView datasource?
Joshua
Usually you have to implement it by yourself like the delegate classes. Every class that implements the NSOutlineViewDataSource Protocol is qualified to become a datasource for an outlineview.
cocoafan
So where do I copy all that code, do I put it in a new class file?
Joshua
Or should I put it in my App Delegate Class File?
Joshua
I tried Pasting it into my Core Data Apps Delegate Class File but it comes up with a load of warnings and an Error saying error befrore '-' token. Here's a Picture of it: http://snapplr.com/xwbf
Joshua
Those are methods you have to implement, you can read how in the docs cocoafan linked to. Of course they're going to generate an error if you literally just paste the headers in you implementation file.
Marc Charbonneau
What methods do I need to implement?
Joshua
Oh, those methods in the post, Ok, i'll have a look in the docs now.
Joshua
I read through the Docs but don't really understand how and where to implement the methods. Can you give me most of the code I need so i can just paste it in?
Joshua
+1  A: 

If you are finding the Apple docs difficult, try reading Jonathan's post about re-ordering.

Okay, well if that's a bit much, try the AbstractTree sample code from Apple's ADC site. The Drag and drop methods are highlighted in the AppDelegate files.

I don't wish to sound rude, but are you working through a tutorial or looking at references? I ask because just requesting code that you can paste in isn't going to be helpful to you: There isn't generic code that you can just drop in. it needs to be written for your specific case. Without knowing about these, we can't just write your methods for you.

Try and implement the example drag and drop methods from AbstractTree, and if you are still having trouble, try posting the code that you have written that isn't working.

Abizern
I have Read it but really only need the code to implement Drag and Drop, but I can't find what code In the Files I would need to do that, Can you tell me?
Joshua
Ok I Had A Go At Implementing It In My xcode project an made sure everything was the same as the one in the example projects, but I got 5 errors, here they are: http://snapplr.com/epks
Joshua
I think the problem may be that you need to work on your understanding of Cocoa and Objective-C. Those 5 errors are fairly self-explanatory and easy to fix; but you seem to have just copied code into your class; which I said wouldn't work.
Abizern
I am un-sure what code I would need to change to work with my code.
Joshua
I have found this tutorial ( http://theocacao.com/document.page/130 )with some code to allow the outline view to use drag and drop, but I am unsure where to put the code. Are you able to tell me?
Joshua
Did you even work through the AbstractTree sample code that I linked to? It takes less than an hour and the drag and drop code is clearly marked in the sample.
Abizern