1

我有这段代码:

NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
[pboard declareTypes:[NSArray arrayWithObject:NSURLPboardType] owner:nil];
[pboard writeObjects:[NSArray arrayWithObject:[NSURL fileURLWithPath:@"/Users/dw/Desktop/macapp/Menulet/logo.png"]]];

而且我不想使用绝对路径,但是当我尝试仅使用“logo.png”时,会出现以下错误:

NSURLs written to the pasteboard via NSPasteboardWriting must be absolute URLs.  NSURL 'logo.png -- file://localhost/Users/dw/Library/Developer/Xcode/DerivedData/Menulet-bvwpfkjlcufhxubvaxubgnubtfgi/Build/Products/Debug/' is not an absolute URL.

反正有没有硬编码它?logo.png 目前在我的 Xcode 资源文件夹中。

编辑: 我怎样才能获得目录路径?

4

1 回答 1

4

这应该是诀窍:

[[NSBundle mainBundle] pathForResource:@"logo" ofType:@"png"]

文档在这里

于 2013-01-16T01:08:21.997 回答