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