Lefora Free Forum
login join
Loading
458 views

Creating drag drop zone from files in NSView

Page 1
1–1
rookie - member
1 posts


Hello, 

I have made a program mostly in C and are now trying to make an interface in Cocoa. I want a drag and drop zone in the interface for files and have been struggling to get this to work. I think, mainly because I'm new to Cocoa and that most examples I have found so far is for images, not files. 

I have created an NSView in my interface and a class called dropZone, where I have the following code so far:


#import "dropZone.h"




@implementation dropZone




- (void)drawRect:(NSRect)rect


{


[self registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, nil]];


// [stringForType : NSFilenamesPboardType]


// [self dragFile:nil fromRect: rect slideBack: false event: nil];



NSRect bounds = [self bounds];


[[NSColor grayColor] set];


[NSBezierPath fillRect:bounds];


}



-(IBAction)getPath:(id)sender{


[textField setStringValue: @"Hello"];


}



@end



What's missing here to be able to complete the operation? What I'm going for here initially is getting the file path. Later on I'd like to restrict the file types that is accepted as well. 

Thanks.

Edit: didn't find any code tags, sorry.




Page 1
1–1

Locked Topic


You must be a member to post in this forum

Join Now!