简体   繁体   中英

.[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

Available in OS X v10.6 and later

But I get the error:

ARC Semantic issue - No visible @interface for 'NSOpenPanel' declares the selector '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. That's why you were seeing the error when trying to resolve the directoryURL:' selector.

The directoryURL property does have a getter and setter, though.

Try using:

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

or:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM