为什么 -[NSPasteboard writeObjects:] 对于 NSURL 对象数组返回 NO?
我有一个 NSArrayController,用于向 IKImageBrowserView 提供数据。我想支持从 IKImageBrowserView 拖放到其他应用程序。这是我的代码中的相关方法:
- (NSUInteger) imageBrowser:(IKImageBrowserView *) aBrowser writeItemsAtIndexes:(NSIndexSet *) itemIndexes toPasteboard:(NSPasteboard *)pasteboard{
NSArray *items = [[resultsArrayController arrangedObjects] objectsAtIndexes:itemIndexes];
if(![pasteboard writeObjects:items]){
return 0;
}
return [items count];
}
我的应用程序是新的,因此我的目标是 10.6+,并根据 文档,“在 Mac OS X v10.6 及更高版本上,使用 writeObjects: 写入而是直接指向粘贴板的 URL。”
我已经验证我尝试写入的对象确实是 NSURL 对象,因此我不确定该过程在哪里发生故障或如何进一步解决问题。预先感谢您的任何帮助。
I have an NSArrayController that I'm using to provide data to an IKImageBrowserView. I want to support drag and drop from the IKImageBrowserView to other applications. Here's the relevant method from my code:
- (NSUInteger) imageBrowser:(IKImageBrowserView *) aBrowser writeItemsAtIndexes:(NSIndexSet *) itemIndexes toPasteboard:(NSPasteboard *)pasteboard{
NSArray *items = [[resultsArrayController arrangedObjects] objectsAtIndexes:itemIndexes];
if(![pasteboard writeObjects:items]){
return 0;
}
return [items count];
}
My app is new so I'm targeting 10.6+ and according to the documentation, "On Mac OS X v10.6 and later, use writeObjects: to write URLs directly to the pasteboard instead."
I've verified that the objects that I am attempting to write are indeed NSURL objects, so I'm not sure where the process is breaking down or how to further troubleshoot the problem. Thanks in advance for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你清除粘贴板了吗?您需要这样做,从而成为粘贴板的所有者,然后才能将对象写入粘贴板。
Have you cleared the pasteboard yet? You need to do that, and thereby become the pasteboard's owner, before you can write objects to the pasteboard.
您是否已验证您的
pasteboard
变量不为零?Have you verified that your
pasteboard
variable is not nil?要发送到 -[NSPasteboard writeObjects:] 的对象是否应该是 NSPasteboadItems?您可以将它们的字符串值设置为 NSURL 的absoluteString 并写入 NSPasteboadItems 数组。
Are the objects that are to be sent to -[NSPasteboard writeObjects:] supposed to be NSPasteboadItems? You can set their string value to the absoluteString of the NSURL and write an array of NSPasteboadItems.