【问题标题】:.[NSOpenPanel directoryURL] gives error: No visible @interface for 'NSOpenPanel' declares the selector 'directoryURL:'.[NSOpenPanel directoryURL] 给出错误:“NSOpenPanel”没有可见的@interface 声明选择器“directoryURL:”
【发布时间】:2015-09-27 20:20:46
【问题描述】:

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

适用于 OS X v10.6 及更高版本

但我得到了错误:

ARC 语义问题 - “NSOpenPanel”没有可见的@interface 声明选择器“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/"]];
    // ...
} 

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

【问题讨论】:

    标签: objective-c macos cocoa nsopenpanel


    【解决方案1】:

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

    directoryURL 属性确实有一个 getter 和 setter。

    尝试使用:

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

    或:

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

    【讨论】:

    • 哎呀,你是对的,它是一个属性。所有这些语言转换都让我的大脑感到困惑。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-19
    • 2017-06-05
    • 2017-10-25
    相关资源
    最近更新 更多