NSView デリゲートを使用して、ドラッグされた Excel 値を読み取ります。このために、NSView をサブクラス化しました。私のコードは次のようなものです-
@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 is the original excel text and its getting displayed.
[self setTextToDisplay:textDataFile];
}
そのクラスの文字列属性に textDataFile 値を設定しています。今、私は SSDragDropView 属性値を他のクラスのように使用しています-
SSDragDropView *dragView = [SSDragDropView new];
NSLog(@"DragView Value is %@",[dragView textToDisplay]);
しかし、私は毎回nullになっています。それらのデリゲート メソッドで属性値を設定できないようなものですか?