为什么 -[NSPasteboard writeObjects:] 对于 NSURL 对象数组返回 NO?

发布于 2024-09-27 01:24:15 字数 842 浏览 8 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

输什么也不输骨气 2024-10-04 01:24:15

你清除粘贴板了吗?您需要这样做,从而成为粘贴板的所有者,然后才能将对象写入粘贴板。

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.

离笑几人歌 2024-10-04 01:24:15

您是否已验证您的 pasteboard 变量不为零?

Have you verified that your pasteboard variable is not nil?

被翻牌 2024-10-04 01:24:15

要发送到 -[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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文