cocoa - Drag Drop delegate for NSView could not set an attribute -
i using nsview delegate read dragged excel values. have subclassed nsview. code like-
@interface ssdragdropview : nsview { nsstring *texttodisplay; } @property(nonatomic,retain) nsstring *texttodisplay; // setters/getters @synthesize texttodisplay;// setters/getters @implementation ssdragdropview - (nsdragoperation)draggingentered:(id <nsdragginginfo>)sender{ [self setneedsdisplay: yes]; return nsdragoperationgeneric; } - (void)draggingexited:(id <nsdragginginfo>)sender{ [self setneedsdisplay: yes]; } - (bool)preparefordragoperation:(id <nsdragginginfo>)sender { [self setneedsdisplay: yes]; return yes; } - (bool)performdragoperation:(id < nsdragginginfo >)sender { nsarray *draggedfilenames = [[sender draggingpasteboard] propertylistfortype:nsfilenamespboardtype]; if ([[[draggedfilenames objectatindex:0] pathextension] isequal:@"xls"]){ return yes; } else { return no; } } - (void)concludedragoperation:(id <nsdragginginfo>)sender{ nsarray *draggedfilenames = [[sender draggingpasteboard] propertylistfortype:nsfilenamespboardtype]; nsurl *url = [nsurl fileurlwithpath:[draggedfilenames objectatindex:0]]; nsstring *textdatafile = [nsstring stringwithcontentsofurl:url usedencoding:nil error:nil]; //this text original excel text , getting displayed. [self settexttodisplay:textdatafile]; }
i setting textdatafile value string attribute of class. using ssdragdropview attribute value in other class like-
ssdragdropview *dragview = [ssdragdropview new]; nslog(@"dragview value %@",[dragview texttodisplay]);
but getting null each time. can not set attribute value in delegate methods?
the above problem can resolved declaring global variable in ssdragdropview.h class.
#import <cocoa/cocoa.h> nsstring *mytexttodisplay; @interface ssdragdropview : nsview {
the same can set inside desired delegate method
- (void)concludedragoperation:(id <nsdragginginfo>)sender { // .... //your code nsstring *textdatafile = [nsstring stringwithcontentsofurl:url usedencoding:nil error:nil]; mytexttodisplay = textdatafile; // .... //your code }
:)
Comments
Post a Comment