docs:programming:cocoa_and_objective-c:drag_and_drop_onto_program_icon

drag and drop onto program icon

  • in Xcode, Get Info on the desired target
  • in the “Properties” tab, add a new document type
    • give the item a name, such as: Tiff Image
    • give the item a UTI, such as: public.tiff
    • set the Store Type to Binary
    • set the Role to Viewer
  • this alone should make an image file dragged onto the program icon appear to work, but nothing will happen yet

In IB (Interface Builder) set a delegate for “File's Owner”, such as MyAppController

Add this to the delegate of “File's Owner”

- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{
	NSFileManager *fm = [NSFileManager defaultManager];
	if([fm isReadableFileAtPath:filename]){
		[self openLocation:filename];
		return YES;
	}
	return NO;
}

- (void)openLocation:(NSString *)newLocation {

if([fileManager fileExistsAtPath:newLocation]){
	// do something
}

}

  • docs/programming/cocoa_and_objective-c/drag_and_drop_onto_program_icon.txt
  • Last modified: 2008/08/03 00:25
  • by 127.0.0.1