I have a MainViewController with splitview in it. Then I have two view managers to manage each of the views in splitview. I want to be able to drag and drop a file in one of these views.
But I canβt get the drag to work? There is no "plus sign" in the file when you drag it into the view and resetting it also does nothing.
What am I doing wrong?
First here is MainViewController.m
fileViewController = [[FileViewController alloc] initWithNibName:@"FileViewController" bundle:nil]; terminalViewController = [[TerminalViewController alloc] initWithNibName:@"TerminalViewController" bundle:nil]; [splitView replaceSubview:[[splitView subviews] objectAtIndex:0] with:[fileViewController view]]; [splitView replaceSubview:[[splitView subviews] objectAtIndex:1] with:[terminalViewController view]];
Then my drag and drop code in FileViewController
@dynamic isHighlighted; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { NSLog(@"registering"); [self.view registerForDraggedTypes:[NSArray arrayWithObjects: NSFilenamesPboardType, nil]]; } return self; } - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender { NSLog(@"[%@ %@]", NSStringFromClass([self class]), NSStringFromSelector(_cmd)); NSPasteboard *pboard = [sender draggingPasteboard]; if ([[pboard types] containsObject:NSFilenamesPboardType]) { NSArray *paths = [pboard propertyListForType:NSFilenamesPboardType]; for (NSString *path in paths) { NSError *error = nil; NSString *utiType = [[NSWorkspace sharedWorkspace] typeOfFile:path error:&error]; if (![[NSWorkspace sharedWorkspace] type:utiType conformsToType:(id)kUTTypeFolder]) { [self setHighlighted:NO]; return NSDragOperationNone; } } } [self setHighlighted:YES]; return NSDragOperationEvery; } - (void)draggingExited:(id <NSDraggingInfo>)sender { [self setHighlighted:NO]; } - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender { return YES; } - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender { [self setHighlighted:NO]; return YES; } - (void)concludeDragOperation:(id )sender { [self.view setNeedsDisplay:YES]; }
source share