2012-08-14 31 views
0

如何编码按钮以启动Mac上文件的搜索,以便用户可以选择文件?该程序将要求用户选择他将要发送到外部设备的文件。指定按钮在Cocoa中搜索计算机文件

+0

也许你正在寻找的(https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ [NSOpenPanel类?] ApplicationKit /班/ NSOpenPanel_Class /参考/的reference.html) – sgress454 2012-08-14 20:40:04

回答

1

听起来像你想使用NSOpenPanelreference)来允许用户选择一个文件。

你使用这样的:

NSOpenPanel *openPanel = [NSOpenPanel openPanel]; 
// Configure the panel if necessary using openPanel.whatever = something; 
NSInteger result = [openPanel runModal]; 
if (result == NSOKButton) 
{ 
    NSURL *url = openPanel.URL; 
    NSAssert(url.isFileURL, @"Expected a file!"); 
    NSString *filename = url.path; 
}