[英].[NSOpenPanel directoryURL] gives error: No visible @interface for 'NSOpenPanel' declares the selector 'directoryURL:'
我正在使用Xcode,使用基本SDK和部署目标构建: OS X 10.8
,试图使用[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"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.