objective c - How do i implement Drag and drop with NSOutlineVIew -


i have 2 nstableviews on screen; want drag row 1 table other table. see lots of tips here , there not see complete example , i'm bit confused. saw examples totally different apples sample apps tableview playground , drag , drop outlineview.

i decided use apples method, im stuck. tableview playground implement these methods in model object.

- (nsarray *)writabletypesforpasteboard:(nspasteboard *)pasteboard - (id)pasteboardpropertylistfortype:(nsstring *)type - (nspasteboardwritingoptions)writingoptionsfortype:(nsstring *)type pasteboard:(nspasteboard *)pasteboard 

i dont understand how set these up. 1st method returned array string @"com.mycompany.myapp.mypasteboardtype"as suggested in this question.

what should put 2nd method? model custom object has number of strings, arrays, , dictionary variables. not understand 3rd method. wish there example see simple drag 1 table custom model object.

edit: implementation based on response below

-(id)pasteboardpropertylistfortype:(nsstring *)type {     return [nskeyedarchiver archiveddatawithrootobject:self]; }  -(nsarray *)writabletypesforpasteboard:(nspasteboard *)pasteboard {     return [nsarray arraywithobject:mydragtype]; } // other methods need implemented  -(id)initwithpasteboardpropertylist:(id)propertylist oftype:(nsstring *)type {     return [nskeyedunarchiver unarchiveobjectwithdata:propertylist]; }  +(nsarray *)readabletypesforpasteboard:(nspasteboard *)pasteboard {     return  [nsarray arraywithobject:mydragtype]; }  // , object needs comply nscoder protocol.  these following 2 methods needs go in object model associated row. -(void)encodewithcoder:(nscoder *)acoder {     [acoder encodeobject:oneofmyivarstoencode forkey:@"somekey"]; }  -(id)initwithcoder:(nscoder *)adecoder {     self = [super init];     if (self) {         oneofmyendodedivars = [adecoder decodeobjectforkey:@"somekey"];     }      return self; } 

what should put [pasteboardpropertylistfortype:]? model custom object has number of strings, arrays, , dictionary variables.

it depends on type you're being asked for.

if it's own custom type made up, can put whatever want. really—if it's type you've invented, can return whatever want here, long it's valid property list. have make sure paste/drop code (pasteboard reading) expecting same stuff.

if want support internal drags (reordering and/or relocation within hierarchy), should have @ least 1 custom type identifies object can same object when accepting drop (in order move rather duplicate it). core data object, might use absolute string of the object's identifying uri.

if want support dragging other applications, should have @ least 1 non-custom type other applications recognize. type(s) support depend on model represents: if they're images (or recipes creating them, such stacks of layers), support png, tiff, jpeg, etc.; if they're contacts, support vcard; if they're text, support plain text and/or rtf and/or html and/or webarchive and/or microsoft word; etc.

you return array of types object can turned writabletypesforpasteboard:; afterward, pasteboardpropertylistfortype: must @ type asked , return property list of type.

for external formats, pasteboardpropertylistfortype: must return data object. own custom formats, it's either dictionary or array of dictionaries, although, said, real requirements must plist of sort , reading code must able understand it.

i not understand [writingoptionsfortype:pasteboard:].

you must return bit mask indicating when , how write type pasteboard. the available options documented.

currently, there's one: can promise data. means pasteboard not ask data; wait until user pastes or drops somewhere (or data otherwise requested application—e.g., poorly-written drop validation method request data , examine during validation, rather drop acceptance). call pasteboardpropertylistfortype: type. (and per-type option; can choose promise types not others.)

promising great data expensive compute and/or store; example, compressed archive (compute) or large image (store).


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -