gpt4 book ai didi

objective-c - .[NSOpenPanel目录URL]给出错误: No visible @interface for 'NSOpenPanel' declares the selector 'directoryURL:'

转载 作者:行者123 更新时间:2023-12-03 16:56:51 30 4
gpt4 key购买 nike

我正在使用 Xcode,使用基础 SDK 和部署目标进行构建:OS X 10.8,尝试使用 offical documentation 中的 [NSOpenPanel directoryURL]说是

Available in OS X v10.6 and later

但我收到错误:

ARC Semantic issue - No visible @interface for 'NSOpenPanel' declares the selector 'directoryURL:'

代码:

#import <Cocoa/Cocoa.h>
// #import <NSOpenPanel.h> // No good
@import AppKit;

void fileOpen()
{
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
// [openPanel setDirectory:@""]; // works, but deprecated in OSX 10.6
[openPanel directoryURL: [NSURL URLWithString:@"file:///path/"]];
// ...
}

那么我在这里做错了什么?

最佳答案

directoryURL 是一个属性,并不像您最初猜测的那样采用字符串参数。这就是您在尝试解析 directoryURL:' 选择器时看到错误的原因。

不过,directoryURL 属性确实有 getter 和 setter。

尝试使用:

[openPanel setDirectoryURL: [NSURL URLWithString:@"file:///path/"]];

或者:

openPanel.directoryURL = [NSURL fileURLWithPath:@"path"];

关于objective-c - .[NSOpenPanel目录URL]给出错误: No visible @interface for 'NSOpenPanel' declares the selector 'directoryURL:' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32812446/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com