我正在使用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/"]];
    // ...
}


那我在做什么错呢?

最佳答案

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

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

尝试使用:

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


要么:

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

关于objective-c - 。[NSOpenPanel directoryURL]给出错误:'NSOpenPanel'的无可见@interface声明选择器'directoryURL:',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32812446/

10-09 01:49