【发布时间】:2012-07-18 19:33:20
【问题描述】:
我想在我的应用程序中实现简单的拖放。 如果您将文件拖到我想返回的窗口中 带有 NSLog 的文件路径。这是我的代码,但是 如果我拖动文件,什么也不会发生。顺便说一句,我 将 AppDelegate 与引用插座连接 使用窗口(委托)从窗口接收所有内容。
AppDelegate.m:
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize window = _window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[_window registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, nil]];
}
-(NSDragOperation)draggingEntered:(id < NSDraggingInfo >)sender
{
return NSDragOperationGeneric;
}
-(BOOL)prepareForDragOperation:(id < NSDraggingInfo >)sender
{
NSPasteboard* pbrd = [sender draggingPasteboard];
NSArray *draggedFilePaths = [pbrd propertyListForType:NSFilenamesPboardType];
// Do something here.
return YES;
NSLog(@"string2 is %@",draggedFilePaths);}
@end
AppDelegate.h:
//
// AppDelegate.h
// testdrag
//
// Created by admin on 18.07.12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
@end
【问题讨论】:
-
这不是 Xcode 问题。
标签: objective-c cocoa xcode4.3