How do you redesign the view, for example in a table view?

How would you display a schematic view that can be reordered (drag and drop to move the position of the row) like a table. The moment I try to drag a row, it just selects other rows. How can I make it redefined?

+1


a source to share


2 answers


You have to implement drag'n drag material .

These are the methods you must implement in your NSOutlineView data source.

- (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;

      



Read more about NSOutlineViewDataSource Protocol Reference .

You also need to register the drag types for your outlineView

[outlineView registerForDraggedTypes: [NSArray arrayWithObjects: NSStringPboardType, NSURLPboardType, NSFilenamesPboardType,NSFileContentsPboardType, nil]];

      

+6


a source


If you're having trouble finding Apple docs, try reading Jonathan 's reorder message .

Ok, if it's a bit, try the AbstractTree sample code from the Apple ADC site. The drag and drop methods are highlighted in the AppDelegate.



I don't mean to sound rude, but are you working through the tutorial or see the links? I am asking because simply asking for code that you can insert will not be helpful to you: there is no generic code that you can just walk in. You need to write for your specific case. Without knowing this, we cannot just write your methods for you.

Try using the drag and drop methods of the example from AbstractTree, and if you still have problems, try posting the code you wrote that doesn't work.

+1


a source







All Articles