[英].[NSOpenPanel directoryURL] gives error: No visible @interface for 'NSOpenPanel' declares the selector 'directoryURL:'
I'm using Xcode, building with base SDK and deployment target: OS X 10.8
, trying to use [NSOpenPanel directoryURL]
which the offical documentation says is 我正在使用Xcode,使用基本SDK和部署目标构建:
OS X 10.8
,试图使用[NSOpenPanel directoryURL]
, 官方文档说的是
Available in OS X v10.6 and later
适用于OS X v10.6及更高版本
But I get the error: 但我得到错误:
ARC Semantic issue - No visible @interface for 'NSOpenPanel' declares the selector 'directoryURL:'
ARC语义问题 - 'NSOpenPanel'没有可见的@interface声明选择器'directoryURL:'
Code: 码:
#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/"]];
// ...
}
So what am I doing wrong here? 那么我在这里做错了什么?
directoryURL
is a property and does not take a string argument like what you were originally guessing. directoryURL
是一个属性,不会像你最初猜测的那样采用字符串参数。 That's why you were seeing the error when trying to resolve the directoryURL:'
selector. 这就是您在尝试解析
directoryURL:'
选择器时看到错误的原因。
The directoryURL
property does have a getter and setter, though. 但是,
directoryURL
属性确实有一个getter和setter。
Try using: 尝试使用:
[openPanel setDirectoryURL: [NSURL URLWithString:@"file:///path/"]];
or: 要么:
openPanel.directoryURL = [NSURL fileURLWithPath:@"path"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.