0
也許是因爲我不知道正確的術語,因此無法在Internet上找到有關我的問題的任何內容。我想要實現的是一個導航窗口,它會在按鈕單擊時打開(當我們讓我們說要將文件添加到項目中時看到的導航窗口,xCode讓我們選擇通過計算機搜索以找到我們想要的文件加)。用於在Mac上查找文件的UI
我究竟能夠實現這種行爲?如果是重複的,請評論,我將刪除該問題。
也許是因爲我不知道正確的術語,因此無法在Internet上找到有關我的問題的任何內容。我想要實現的是一個導航窗口,它會在按鈕單擊時打開(當我們讓我們說要將文件添加到項目中時看到的導航窗口,xCode讓我們選擇通過計算機搜索以找到我們想要的文件加)。用於在Mac上查找文件的UI
我究竟能夠實現這種行爲?如果是重複的,請評論,我將刪除該問題。
你所尋找的是所謂NSOpenPanel
用法示例:
- (NSInteger) showFilepanel{
self.filePanel = [NSOpenPanel openPanel];
[self.filePanel setAllowsMultipleSelection:NO]; //This will allow the user to select multiple files
[self.filePanel setCanChooseDirectories:NO]; //If you want the user to select lets say a path to save a file, you should enable this so he can select the directory
[self.filePanel setCanChooseFiles:YES]; // For selecting only files (like in an Open File-scenario)
return [self.filePanel runModal]; //This will return 0 if the user cancelled
}
然後,您可以讀出這樣選擇的路徑:
- (void) savePathFromPanel{
NSString *path = [[self.panel URLs] objectAtIndex:0];
//Do now what you want with the selected path
}